forked from koalaman/shellcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
SC2004
Vidar Holen edited this page Oct 4, 2015
·
2 revisions
echo $(($n+1))echo $((n+1))The $ on regular variables in arithmetic contexts is unnecessary, and can even lead to subtle bugs. This is because the contents of $((..)) is first expanded into a string, and then evaluated as an expression:
$ a='1+1'
$ echo $(($a * 5)) # becomes 1+1*5
6
$ echo $((a * 5)) # evaluates as (1+1)*5
10The $ is unavoidable for special variables like $1 vs 1, $# vs #. ShellCheck does not warn about these cases.