Open laurenthuberdeau opened 2 months ago
I'm not sure where you have tried but with this:
foo=1
var1="foo"
echo $(($var1))
echo $((var1))
you get:
1
1
I have tried both in bash
and busybox ash
.
I use dash which outputs:
1
test.sh: 4: Illegal number: foo
Curiously, ash, bash, ksh and zsh all seem to do the same thing where variables are recursively expanded until variables (except for variables that appear left in assignment operators) no longer appear in the expression. Dash seems to only expand each variables once and so it errors on foo
as it's not a valid integer literal.
Take this code for example:
baz=12
bar="baz"
foo="bar"
var1="foo"
echo $(($var1))
echo $((var1))
It produces on bash, ksh, zsh:
12
12
while dash produces:
test.sh: 5: Illegal number: bar
@koalaman I think that SC2004 should be skipped for dash and there should be a new rule specific to dash that say to avoid multiple levels of "variable variables".
For bugs
SC2004
shellcheck --version
or "online"):0.10.0
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
In POSIX shell, indirect expansion of numeric variables can be done using variable expansion in arithmetic expansion.
$((var1))
is not equivalent to$(($var1))
, the first returns0
and the second12
.The https://www.shellcheck.net/wiki/SC2004 page should mention this exception.