help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] The difference between $* and "$*"?


From: Eric Blake
Subject: Re: [Help-bash] The difference between $* and "$*"?
Date: Mon, 03 Feb 2014 06:59:00 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 02/02/2014 01:58 PM, Chet Ramey wrote:
> On 2/1/14, 1:58 PM, Seth David Schoen wrote:
>> Peng Yu writes:
>>>
>>> I'm trying to understand the different between $* and "$*". The
>>> following shows that they behave differently when IFS is not the
>>> default. But the above paragraph from the manual does not explain
>>> this. Could anybody let me know if this is documented somewhere else
>>> in the manual and how to understand the difference? Thanks.
>>
>> Hi,
>>
>> The difference is whether it "expands to a single word" or to multiple
>> words.
> 
> Would it help to add this sentence?
> 
> "When not within double quotes, each positional parameter expands to a
> separate word."
> 
> It seems to me that that could have eliminated the confusion.

No, because that's not quite true.  Eliminating the quotes means that
positional parameters are ALSO subject to word-splitting:

$ set -- 'a  b' 'c'
$ args() { printf "$#:"; for arg; do printf " -$arg-"; done; echo; }
$ args $*
3: -a- -b- -c-
$ args "$*"
1: -a  b c-

If each parameter expands to a separate word, with no further word
splitting, then I would have expected output of "2: -a  b- -c-".

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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