Skip to content
Vidar Holen edited this page Jan 21, 2015 · 10 revisions

Remove space after = if trying to assign a value (or for empty string, use var='' ... ).

Problematic code:

# I want programs to show text in dutch!
LANGUAGE= nl

# I want to run the nl command with English error messages!
LANGUAGE= nl

Correct code:

# I want programs to show text in dutch!
LANGUAGE=nl

# I want to run the nl command with English error messages!
LANGUAGE='' nl

Rationale:

It's easy to think that LANGUAGE= nl would assign "nl" to the variable LANGUAGE. It doesn't.

Instead, it runs nl (the "number lines" command) and sets LANGUAGE to an empty string in its environment.

Since trying to assign values this way is a common mistake, ShellCheck warns about it and asks you to be explicit when assigning empty strings (except for IFS, due to the common IFS= read .. idiom).

Exceptions

If you're familiar with this behavior and feel that the explicit version is unnecessary, you can ignore the message. alias shellcheck=`shellcheck -e SC1007`

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