"local" is a shell reserved word, isn't it?
Cristian Ionescu-Idbohrn
cristian.ionescu-idbohrn at axis.com
Mon Nov 22 17:22:12 UTC 2010
On Mon, 22 Nov 2010, Bernd Petrovitsch wrote:
> On Son, 2010-11-21 at 18:39 -0500, Paul Smith wrote:
> > On Mon, 2010-11-22 at 00:25 +0100, Cristian Ionescu-Idbohrn wrote:
> > > Different shells (ash, dash, bash) handle the above in an unexpected
> > > way. I would have expected a consistent:
> > >
> > > foo: line 7: syntax error: bad function name
> >
> > "local" is not a reserved word in POSIX. There is no "local" keyword or
> > definition in the POSIX shell.
>
> In theory, it's not in POSIX. In practice, it's a keyword in bash. And
> that's in the world today probably more important and relevant.
Right. That's what I was thinking of. "local" is not POSIX, but it's
implemented in ash. Might as well be implemented right. And, FWIW, dash
missbehaves similarily, but bash cares about it. Tried this alternative
example:
,----
| #!/bin/sh
|
| set -e
| set -u
| #set -x
|
| eval() {
| local eval
| eval eval=$1
| echo "func: 'eval', local var eval='$eval'"
| }
|
| eval user=$LOGNAME
`----
It showed the expected:
foo: line 7: syntax error: bad function name
I don't see why "local" should behave different.
Cheers,
--
Cristian
More information about the busybox
mailing list