Re: Parameter expansion fails when assigning a local variable

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


Jesper Bengtsson <jesper.bengtsson@xxxxxxxx> wrote:
> 
> I've found a problem with expanding $@.
> If I declare a local variable and assigns the expanded positional parameters:
>        local v="$@"
> It fails with something like:
>        local: 20: \/: bad variable name

This is expected behaviour.  local is just like any other utility
in how it handled parameters.  So "$@" will have been split before
it reaches local.  To get what you want, you should use "$*".
 
> I've tried this on dash 0.5.5.1 and 0.5.3 and both fail in the same way.
> I've also tried on bash and ash (Busybox) and both handles declaration and assignment on one line.

Bash and older versions of dash (like the one in Busybox) has a
hack that disables field splitting for local and certain other
commands.  This is not guaranteed by POSIX.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
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

[LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

Powered by Linux