Skip to content

assignment-not-seen

Shellcorrectnessno fixdefault: offshell/shellcheck

Reports var=value cmd "$var", where $var is used in the arguments of the command that the assignment is a prefix of.

The shell expands the arguments before the command runs, and the prefix assignment takes effect only in the command’s environment. $var in the arguments is the old value (often empty), not value.

To fix, assign on its own line, or read the variable inside the command.

Reported
...
for l in "$@"; do :; done
...
A=1 echo "$A"
A=1 cmd "$B"
A=1 cmd "$A_"
...
shell:
lint:
rules:
assignment-not-seen: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line assignment-not-seen in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
shellcheck SC2097 full
shellcheck SC2098 partial Only an expansion inside a double-quoted argument.