Using MAC OS X and bourne shell:
I like to iterate through a list of items, for which some of the items include blanks. Each item should be treated as a whole, but they are splitted as shown below. If I "hard code" it like this, it is ok:
echo "hard coded :\n"
for i in 'a a a' 'bcd' 'e e'
do
echo "$i"
done
But putting the same string into a variable, it is wrong:
echo "\nsecond loop:\n"
#
# str is normally coming from a comma substitution
str="'a a a' 'bcd' 'e e'"
echo $str
for i in ${str}
do
echo "$i"
done
The result is:
hard coded :
a a a
bcd
e e
second loop:
'a a a' 'bcd' 'e e'
'a
a
a'
'bcd'
'e
e'