[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Is there a particular reason that $@ is expanded to a string
From: |
ziyunfei |
Subject: |
[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: |
Sun, 6 Sep 2015 12:11:08 +0800 |
$ 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”.
- [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?,
ziyunfei <=