0

So the following commands are giving me different answers than I expect.

Code:

#!/bin/sh

array_2=('1 2' 3 4)

echo With '"$@":'

for i in "${array_2[@]}"
do
    echo $i
done


echo With '$@:'

for i in ${array_2[@]}
do
    echo $i
done 

Output:

With "$@":
1 2
3
4


With $@:
1
2
3
4

Why is $@ "not seeing" that '1 2' are enclosed by single quotes, when "$@" can?

Jack Park
  • 9
  • 1
  • Variables are not expanded inside single quotes. – stark May 04 '21 at 19:50
  • Somebody posted this and was deleted but here it is again, this will/should give you the answers you need. https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable – Jetchisel May 04 '21 at 19:57

0 Answers0