-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
For bugs with existing features
- Rule Id: Various, see snippet descriptions.
- My shellcheck version: 0.11.0
- The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
Here's a snippet or screenshot that shows the problem:
Arithmetic operations, $(( ... )), can contain variable assignments (e.g. var = 1); however, this breaks shellcheck's parsing and causes various unrelated errors if the assignments aren't wrapped in brackets (e.g. (var = 1)).
#!/bin/sh
arg="$1" var2=""
var="$(( arg < 2 ? var2 = 1 : 0 ))"
echo "$var : $var2"What this script prints when executed by sh, ksh, bash, or dash (no difference if POSIXLY_CORRECT=1 is set):
$ ./script.sh 1
1 : 1
$ ./script.sh 2
0 : Shellcheck suggests the following SCs for the script above: 1102, 2034, and 2210.
#!/bin/sh
arg="$1" var2=""
var="$((
arg < 2
? var2 = 1
: 0
))"
echo "$var : $var2"What this script prints when executed by sh, ksh, bash, or dash (no difference if POSIXLY_CORRECT=1 is set):
$ ./script.sh 1
1 : 1
$ ./script.sh 2
0 : When the operations is written over multiple lines, Shellcheck additionally suggests SC2211 with the previously listed SCs.
If (var2 = 1) is used instead of var2 = 1, no SCs are suggested when using either version of the operation.
Here's what shellcheck currently says:
See above.
Here's what I wanted or expected to see:
Shellcheck should handle arithmetic operations containing bracket-less variable assignments which, as far as I can tell, is valid syntax for POSIX shell, Korn shell, Bash, and Dash.