[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
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?
Sun, 6 Sep 2015 21:00:11 +0100
2015-09-06 12:11:08 +0800, ziyunfei:
> $ 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? And I found a
> possibily relevant comment in the Bash source code
> http://code.metager.de/source/xref/gnu/bash/subst.c#8858, it
> says “it's what other shells seem to do”.
You may want to read this thread at the Austing group mailing