I have this script:
#!/bin/bash
list="a b c d"
for item in ${list[@]}; do
echo "${item}"
done
When I run it this is the output:
a
b
c
d
This is exactly what I want. However, shellcheck
hates this and throws an error:
for item in ${list[@]}; do
^-- SC2068: Double quote array expansions to avoid re-splitting elements.
But, when I double quote the variable the output of the script changes to this:
a b c d
Which is not what I want.
Is shellcheck right and should I modify the way I try to extract the items from the variable, but how? Or should I just tell shellcheck
to ignore this?