Updated SC2097 (markdown)

Vidar Holen
2020-11-18 14:54:36 -08:00
parent d687b2d023
commit 6934683d83

@@ -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