help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Is there a particular reason that $@ is expanded to a st


From: Chet Ramey
Subject: Re: [Help-bash] Is there a particular reason that $@ is expanded to a string *using a space as separator instead of $IFS* in contexts where word splitting is not performed?
Date: Tue, 8 Sep 2015 09:51:27 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

On 9/6/15 12:11 AM, ziyunfei wrote:
> $ set -- 1 2 3
> $ IFS=:
> $
> $ # in a [[...]] command
> $ [[ $@ == "1 2 3" ]]; echo $? 
> 0 # print 1 in zsh
> $ [[ $@ == "1:2:3" ]]; echo $?
> 1 # print 0 in zsh
> $
> $  # in the rhs of an assignment statement
> $ foo=$@
> $ IFS=
> $ echo $foo
> 1 2 3 # print 1:2:3 in zsh
> 
> $* use the first character of $IFS as separator in these cases but $@
> doesn’t. Does POSIX standard mention this, or this is just a historical
> behavior of Bourne shell?

Both.

http://austingroupbugs.net/view.php?id=888

The key is that $@ expands to multiple fields regardless of whether or not
field splitting is performed, so you have to decide how to join those
fields together into a string.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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