1
0
mirror of https://github.com/koalaman/shellcheck.git synced 2025-01-03 09:47:32 -08:00

Created SC2121 (markdown)

koalaman 2014-03-01 16:03:48 -08:00
parent 7358c6c49b
commit da8884969b

20
SC2121.md Normal file

@ -0,0 +1,20 @@
# To assign a variable, use just 'var=value', no 'set ..'.
### Problematic code:
set var=42
set var 42
### Correct code:
var=42
### Rationale:
`set` is not used to set or assign variables in Bourne shells. It's used to set shell options and positional parameters.
To assign variables, use `var=value` with no `set` or other qualifiers.
### Contraindications
If you actually do want to set positional parameters, simply quoting them or using `--` will make shellcheck stop warning, e.g. `set -- var1 var2` or `set "foo=bar"`.