-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2149
Turiok edited this page Feb 16, 2025
·
6 revisions
Note: Removed in v0.5.0 - 2018-06-01
# Regular array
index=42
echo $((array[$index]))
or
# Associative array
index=banana
echo $((array[$index]))
# Regular array
index=42
echo $((array[index]))
or
# Associative array
index=banana
echo $((array[\$index]))
For a numerically indexed array, the $
is mostly pointless and can be removed like in SC2004.
For associative arrays, the $
should be escaped to avoid accidental dereferencing:
declare -A array
index='$1'
array[$index]=42
echo "$(( array[$index] ))" # bash: array: bad array subscript
echo "$(( array[\$index] ))" # 42
None.