On 08/18/2011 08:38 AM, Sam Steingold wrote:
mkdir z
cd z
touch a b 'c d'

When doing exercises like this, I like to:

touch a b 'c  d'

Notice the double spacing - it proves whether I used enough quoting throughout the exercise - if 'c d' with one space shows up anywhere, then I missed quoting, because word splitting followed by argument concatenation with only one space must have happened.


how do I write a function that would print the same as
$ \ls | cat
a
b
c d

$ f1(){ for a in "$*"; do echo $a; done; }

Incorrect quoting on $a. Also, remember the difference between $* and $@ inside "" - the former creates only one word, and only the latter splits the result into the same number of words as were originally arguments to the function. You meant:

f(){ for a; do echo "$a"; done; }

or

f(){ for a in "$@"; do echo "$a"; done; }

(both are identical).

--
Eric Blake   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Reply via email to