mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Created SC2121 (markdown)
20
SC2121.md
Normal file
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"`.
|
Reference in New Issue
Block a user