Re: [BUG] dash uses $* instead of $@ in variable assignments

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

 



2015-11-26 20:44:26 +0100, Gioele Barabucci:
> Hello,
> 
> I am forwarding a bug [1] reported by a Debian user: dash incorrectly
> uses `$*` instead of the requested `$@` inside variable assignments.
> The current version of dash is affected by this bug.
> 
> A simple test from the original reporter:
> 
>     $ dash -c 'IFS=:$IFS ; set -- a b c ; echo "$@" ; x="$@" ; echo "$x"'
>     a b c
>     a:b:c
[...]

This behaviour is what I expect and is common to other shells as
well.

$* and $@ are the concatenation of the positional parameters
with the first character of $IFS, but "$@" in list contexts
expands to all the position parameters as separate words. That's
a logical continuation to the Bourne behaviour (which
concatenated on space instead of the first character of $IFS).

POSIX used to be unclear about it. I had raised the issue some
time ago and I beleive there's a new wording. See the longish
discussion at
http://thread.gmane.org/gmane.comp.standards.posix.austin.general/9972

In any case, you should only use $@ quoted and in list contexts.
$* may be used quoted in non-list contexts.

IIRC the proposed new wording for the POSIX spec would make this
behaviour of dash non-conformant:

$ dash -c 'set a b c; IFS=; echo $*'
abc

(even though I'd argue it's a logical design choice).

-- 
Stephane

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux