Skip to content
Joachim Ansorg edited this page Nov 12, 2021 · 4 revisions

To assign a variable, use just var=value, not 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.

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

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally