From: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Jesper Bengtsson <jesper.bengtsson@axis.com>, dash@vger.kernel.org
Subject: Re: Parameter expansion fails when assigning a local variable
Date: Sun, 28 Jun 2009 23:39:16 +0200 (CEST) [thread overview]
Message-ID: <0906282220250.1491@somehost> (raw)
In-Reply-To: <20090622085729.GA22431@gondor.apana.org.au>
On Mon, 22 Jun 2009, Herbert Xu wrote:
> Jesper Bengtsson <jesper.bengtsson@axis.com> 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.
Hmm... Why is it so? Because it's the only "natural" expectation?
> local is just like any other utility
Utility? Not built-in? Documentation refers to it as command. Same
thing?
> in how it handled parameters. So "$@" will have been split before
> it reaches local. To get what you want, you should use "$*".
But wait a second. Shouldn't quotes '"' around $@ protect the whole $@?
It does so in different other context. Why not here?
> > 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
Hack. Is that a hack? It is not expected behaviour. It's a hack?
Even newer/recent/latest versions of (busybox) ash have that "hack".
And dash claims to be the only POSIX "true" implementation?
> that disables field splitting for local and certain other
> commands. This is not guaranteed by POSIX.
Sure. That's what it looks like. POSIX doesn't even mention it, does it?
Still. Quotes around $@ should protect it, shouldn't it?
local v="$@"
should expand to:
v="'arg1' 'arg2' ..."
shouldn't it?
There's som parallel unnatural behaviour I noticed:
local var=$(some forked thing here)
$(...)
^^ ^ doesn't seem to protect the resulting string. There seems to be a
difference between:
local h=$(grep --help)
and:
local h="$(grep --help)"
Can anything motivate that? Is that POSIX too?
Cheers,
--
Cristian
next prev parent reply other threads:[~2009-06-28 22:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-22 8:13 Parameter expansion fails when assigning a local variable Jesper Bengtsson
2009-06-22 8:57 ` Herbert Xu
2009-06-28 21:39 ` Cristian Ionescu-Idbohrn [this message]
2009-06-29 0:47 ` Herbert Xu
2009-06-29 17:10 ` Cristian Ionescu-Idbohrn
2009-06-30 1:38 ` Herbert Xu
2009-06-30 16:17 ` Cristian Ionescu-Idbohrn
2009-07-01 7:42 ` Oleg Verych
2009-07-02 16:53 ` Cristian Ionescu-Idbohrn
2009-07-03 21:14 ` Oleg Verych
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0906282220250.1491@somehost \
--to=cristian.ionescu-idbohrn@axis.com \
--cc=dash@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=jesper.bengtsson@axis.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox