Skip to content

eval-array

Shellsuspiciousno fixdefault: offshell/shellcheck

Reports an eval whose argument expands an array with [@].

eval joins its arguments with spaces and parses the result again, so the quoting that the array elements had is lost, and an element with a space or a ; is read as code.

To fix, avoid eval: run the array as a command, "${cmd[@]}".

Reported
...
for l in "$@"; do :; done
eval "f ${args[@]}"
...
A=1 cmd "$B"
A=1 cmd "$A_"
...
shell:
lint:
rules:
eval-array: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line eval-array 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 SC2294 partial Only ${name[@]} inside an eval command.