Created SC2209 (markdown)

koalaman
2017-04-15 10:23:43 -07:00
parent 6468bb013c
commit 1a30ea83db

27
SC2209.md Normal file

@@ -0,0 +1,27 @@
## Use var=$(command) to assign output (or quote to assign string).
### Problematic code:
```sh
user=whoami # Want to run whoami and assign output
PAGER=cat git log # Want to assign the string "cat"
```
### Correct code:
```sh
user=$(whoami)
PAGER="cat" git log
```
### Rationale:
Putting `var=` in front of a command will not assign its output. Use `var=$(my command here)` to execute the command and capture its output.
If you do want to assign a literal string, use quotes to make this clear to shellcheck and humans alike.
### Exceptions:
None.