Inside which type of parenthesis (), (()), {}, [[ ]], $( ), $(( ))
should we use the dollar sign before the variable to expand it?
CodePudding user response:
The arithmetic expansion is the one that doesn't need dollar sings, which means both ((...))
and $((...))
. But you don't need the dollar sign in other arithmetic contexts, either, e.g. in array indices.
arr=(a b c)
x=1
echo "${arr[x]}" # b
See "Arithmetic Evaluation" in man bash
.