[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 07:05:45 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
On 02/03/2014 06:59 AM, Eric Blake wrote:
>> "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-".
Another proof that word-splitting is performed on the results of
unquoted $* (at least in contexts where word-splitting matters):
$ set -- 'a b' 'c:d'
$ IFS=:
$ args $*
3: -a b- -c- -d-
$ IFS=': '
$ args $*
4: -a- -b- -c- -d-
$ IFS=$' \t\n'
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
Re: [Help-bash] The difference between $* and "$*"?, Bob Proulx, 2014/02/01