bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conditional aliases are broken


From: Eric Blake
Subject: Re: conditional aliases are broken
Date: Thu, 18 Aug 2011 08:44:45 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

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   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]