Skip to content
koalaman edited this page Oct 11, 2016 · 3 revisions

To assign the output of a command, use var=$(cmd) .

Problematic code:

var=grep -c pattern file

Correct code:

var=$(grep -c pattern file)

Rationale:

To assign the output of a command to a variable, use $(command substitution). Just typing a command after the = sign does not work.

Exceptions:

None.

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