Skip to content

Files

Latest commit

 

History

History
30 lines (18 loc) · 655 Bytes

SC2121.md

File metadata and controls

30 lines (18 loc) · 655 Bytes

Pattern: Use of set to assign variable

Issue: -

Description

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.

Example of incorrect code:

set var=42
set var 42

Example of correct code:

var=42

Exceptions

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".

Further Reading