Skip to content
koalaman edited this page Feb 7, 2016 · 4 revisions

Shells differ in parsing ambiguous $(((. Use spaces: $( (( .

Problematic code:

echo "$((( n > 0)) && mycommand --flags)"

Correct code:

echo "$( (( n > 0)) && mycommand --flags)"

Rationale:

You are using $((( (or ((() to mean $( ((: command expansion with an arithmetic command. The more common interpretation is $(( (: arithmetic expansion with parentheses.

This is an ill-defined structure that is parsed differently between different shells and shell versions. Prefer adding a space to make it unambiguous, both to shells and humans.

Consider the $((( in $(((1)) ):

Ash, dash and Bash 1 parses it as $(( ( and subsequently fail to find the matching )). Zsh and Bash 2+ looks ahead and parses it as $( ((. Ksh parses it as $( ( (.

Exceptions:

None.

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