Skip to content
Vidar Holen edited this page Jul 31, 2021 · 3 revisions

When eval'ing @Q-quoted words, use * rather than @ as the index.

Problematic code:

eval "$MYCOMMAND ${@@Q}"

Correct code:

eval "$MYCOMMAND ${*@Q}"

Rationale:

ShellCheck noticed that you are calling eval and including an escaped array. However, the array is passed as multiple arguments and relies on being implicitly joined together to form a single shell string, which eval can then evaluate.

Instead, prefer building your shell string with explicit string concatenation by using * instead of @ for the index, such as ${*@Q} or ${array[*]@Q}.

This suggestion is equivalent to SC2124, but for eval arguments rather than string variables.

Exceptions:

None.

Related resources:

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!

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