From 6934683d83665d7d3b06fc2459e58bd172e289a8 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 18 Nov 2020 14:54:36 -0800 Subject: [PATCH] Updated SC2097 (markdown) --- SC2097.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SC2097.md b/SC2097.md index 72582dc..627ee94 100644 --- a/SC2097.md +++ b/SC2097.md @@ -9,15 +9,15 @@ name=World cmd -m "Hello $name" ### Correct code: ```sh -export name=World +name=World cmd -m "Hello $name" ``` -To prevent setting the variable, this can also be done in a subshell: +If the original goal was to limit the scope of the variable, this can also be done in a subshell: ```sh ( - export name=World + name=World cmd -m "Hello $name" ) # 'name' does not leave this subshell ``` @@ -28,7 +28,7 @@ In `name=World cmd "$name"`, `name=World` is passed in as part of the environmen However, `"$name"` is not expanded by `cmd`. `"$name"` is expanded by the shell before `cmd` is ever executed, and thus it will not use the new value. -The solution is to set the variable and export the variable first. If limited scope is desired, a `( subshell )` can be used. +The solution is to set the variable first, then use it as a parameter. If limited scope is desired, a `( subshell )` can be used. ### Exceptions