3 SC2037
Joachim Ansorg edited this page 2021-11-12 19:22:54 +01:00

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.