Skip to content
Joachim Ansorg edited this page Nov 12, 2021 · 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.

This warning triggers generally for var=value -flag and var=value *glob*. See related warning SC2209 which matches var=commonCommand.

ShellCheck

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

Clone this wiki locally