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