Loop over set of strings containing spaces

You need to wrap the variables within double quotes, both in all=("$x" "$y") and "${all[@]}":

x="a b"
y="c d"

echo "Attempt XX"
all=("$x" "$y")
for i in "${all[@]}" ; do
  echo "$i"
done

Which yields:

Attempt XX
a b
c d

You can also define the strings with:

all=("a b" "c d")
for i in "${all[@]}" ; do
  echo "$i"
done

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)