From: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Cc: Jesper Bengtsson <jesper.bengtsson@axis.com>, dash@vger.kernel.org
Subject: Re: Parameter expansion fails when assigning a local variable
Date: Mon, 29 Jun 2009 19:10:29 +0200 [thread overview]
Message-ID: <0906291823520.16266@somehost> (raw)
In-Reply-To: <20090629004750.GA2019@gondor.apana.org.au>
On Mon, 29 Jun 2009, Herbert Xu wrote:
> On Sun, Jun 28, 2009 at 11:39:16PM +0200, Cristian Ionescu-Idbohrn wrote:
> >
> > But wait a second. Shouldn't quotes '"' around $@ protect the whole
> > $@? It does so in different other context. Why not here?
>
> The whole point of $@ is to retain field splitting within double
> quotes:
Sure. Quoted, like "$@". I've no problem with that.
> > There's some 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?
>
> As I said local is identical to any other utility in this respect,
> including shell functions.
Ok. You're telling us how it's implemented in dash. Other shells do it
different. Are you implying dash is the only shell which does that thing
right? Even though it is unnatural?
Let's try something else. busybox ash and bash are doing the right thing.
dash and zsh got it wrong. What do people think?
Please consider this example script:
---8<---
#!/bin/dash
set -e
#set -x
func() {
local i=0 v xx="$@"
for v; do
i=$(($i + 1))
echo "func arg. $i: '$v'"
done
echo "inside func: NOONE_SHOULD_TOUCH_THIS=$NOONE_SHOULD_TOUCH_THIS"
}
NOONE_SHOULD_TOUCH_THIS=protected
echo "main, bef. func: NOONE_SHOULD_TOUCH_THIS=$NOONE_SHOULD_TOUCH_THIS"
func "$@"
echo "main, aft. func: NOONE_SHOULD_TOUCH_THIS=$NOONE_SHOULD_TOUCH_THIS"
exit 0
---8<---
and run the script like this:
$ <script path> abc NOONE_SHOULD_TOUCH_THIS=overwritten
Is it the intended behaviour? Should one be able to overwrite script
function variables from command line?
Cheers,
--
Cristian
next prev parent reply other threads:[~2009-06-29 17:10 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
2009-06-29 0:47 ` Herbert Xu
2009-06-29 17:10 ` Cristian Ionescu-Idbohrn [this message]
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=0906291823520.16266@somehost \
--to=cristian.ionescu-idbohrn@axis.com \
--cc=dash@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.