Date: Mon, 03 Dec 2012 11:24:20 -0600 From: Bryan Drewery <bryan-lists@shatow.net> To: rank1seeker@gmail.com Cc: hackers@freebsd.org Subject: Re: $* and $@ exhibit same behaviour -> those of $* Message-ID: <50BCE044.3050202@shatow.net> In-Reply-To: <20121203.170951.188.1@DOMY-PC> References: <20121203.170951.188.1@DOMY-PC>
index | next in thread | previous in thread | raw e-mail
On 12/3/2012 11:09 AM, rank1seeker@gmail.com wrote:
> I've noticed this under 9.0-RELEASE-p5
>
>
> #!/bin/sh
> #####################################################
> ftest_dot ()
> {
> local i
>
> for i in $*
> {
> echo "$i"
> }
> }
>
> ftest_monkey ()
> {
> local i
>
> for i in $@
> {
> echo "$i"
> }
> }
>
>From my understanding, used in that context, they should be the same.
$* Expands to the positional parameters, starting from one. When
the expansion occurs within a double-quoted string it
expands to
a single field with the value of each parameter separated
by the
first character of the IFS variable, or by a space if IFS is
unset.
$@ Expands to the positional parameters, starting from one. When
the expansion occurs within double-quotes, each positional
param‐
eter expands as a separate argument. If there are no
positional
parameters, the expansion of @ generates zero arguments, even
when @ is double-quoted. What this basically means, for
example,
is if $1 is “abc” and $2 is “def ghi”, then "$@" expands
to the
two arguments:
"abc" "def ghi"
Note the first sentence in both. The difference only occurs when used
inside quotes, i.e. "$@" and "$*"
Bryan
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50BCE044.3050202>
