diff --git a/SC1102.md b/SC1102.md index 0e1bd70..9573363 100644 --- a/SC1102.md +++ b/SC1102.md @@ -1,21 +1,21 @@ -## Shells differ in parsing ambiguous $(((. Use spaces: $( (( . +## Shells disambiguate $(( differently or not at all. If the first $( should start command substitution, add a space after it. ### Problematic code: ```sh -echo "$((( n > 0)) && mycommand --flags)" +echo "$((cmd "$@") 2>&1)" ``` ### Correct code: ```sh -echo "$( (( n > 0)) && mycommand --flags)" +echo "$( (cmd "$@") 2>&1)" ``` ### Rationale: -You are using `$(((` (or `(((`) to mean `$( ((`: command expansion with an arithmetic command. The more common interpretation is `$(( (`: arithmetic expansion with parentheses. +You appear to be using `$((` with two (or more) parentheses in a row, where the first `$(` should open a subshell. -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. +This is an ill-defined structure that is parsed differently between different shells and shell versions. Prefer adding spaces to make it unambiguous, both to shells and humans. Consider the `$(((` in `$(((1)) )`: @@ -23,4 +23,6 @@ Ash, dash and Bash 1 parses it as `$(( (` and subsequently fail to find the matc ### Exceptions: -None. \ No newline at end of file +**Alternatively**, you may indeed have correctly spaced your parentheses, but ShellCheck failed to parse `$((` as an arithmetic expression while accidentally succeeding in parsing it as `$(` + `(`. + +In these cases, double check the syntax to ensure ShellCheck can parse the `$((`, or ignore this error and hope that it won't affect analysis too severely. \ No newline at end of file