At some point in my script I need to save value of all command line
arguments in a variable (after some shifting), it looks like this:
foo="$@"
Now I need to interate through the arguments from foo variable, but it
seems to be quite hard to do it properly if there are arguments containing
write space. If I write
for i in "$foo"
do
echo "$i"
done
Everything is printed on one line, indicating that for thinks there is
only one argument. On the other hand:
for i in $foo
do
echo "$i"
done
seems to do the right thing, but it fails too when there are arguments containing write space:
$ my_script one two "three four"
one
two
three
four
In this example three and four should be printed on the same line.
How to iterate though arguments saved in a variable properly?