forked from koalaman/shellcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
SC2128
Vidar Holen edited this page Oct 4, 2015
·
3 revisions
myarray=(foo bar)
for f in $myarray
do
cat "$f"
done
myarray=(foo bar)
for f in "${myarray[@]}"
do
cat "$f"
done
When referencing arrays, $myarray
is equivalent to ${myarray[0]}
-- it results in only the first of multiple elements.
To get all elements as separate parameters, use the index @
(and make sure to double quote). In the example, echo "${myarray[@]}"
is equivalent to echo "foo" "bar"
.
To get all elements as a single parameter, concatenated by the first character in IFS
, use the index *
. In the example, echo "${myarray[*]}"
is equivalent to echo "foo bar"
.
None.