All of lore.kernel.org
 help / color / mirror / Atom feed
* sensible "local" support?
@ 2010-11-07 13:17 Jim Meyering
  2010-11-07 18:28 ` Jonathan Nieder
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Meyering @ 2010-11-07 13:17 UTC (permalink / raw)
  To: dash

Hi Herbert,

Would you be open to the idea of making dash's "local" work more
like the scope modifier that its name implies than like a separate
command in which assignments have different semantics?

To be clear, "local" is not standardized, so the change I'm advocating
would not be a bug fix ;-)  However, it would make dash align with
bash and zsh, and imho, with common sense.

Here's what I mean:

Currently, variable assignments like var=$other_var
require no quotes around the RHS.  That's covered by POSIX.
However, when you want to reduce the scope of that "var"
and use "local var=$other_var", you have subtly changed
semantics in dash, (but not with bash or zsh).
The local-using assignment appears to work, but evokes
a "bad variable name" warning and causes failure:

This works fine:

    $ dash -c 'f() { b="1 1"; z=$b; echo "$z"; }; f'
    1 1

However with "local" on the latter assignment, it fails:

    $ dash -c 'f() { b="1 1"; local z=$b; echo "$z"; }; f'
    local: 1: 1: bad variable name
    1
    [Exit 1]

Regards,

Jim

PS, this started when I noticed FreeBSD 8.1's /bin/sh doing something
odd with local and IFS, and on that basis decided to eliminate it from
the list of candidate shells used for running coreutils tests.  Then I
noticed that dash did the same thing.  I don't want to disqualify dash,
so am hoping to minimize fragmentation in how shells treat "local".

Actually, here's a much better way to demonstrate the problem:
(this is using 016b529d2b114efc6cd91fe4e3e4767ba615870a, the latest
from the dash.git repository):

    $ ./dash -c 'f() { b="1 x=3"; local z=$b; echo "z=<$z> x=<$x>"; }; f'
    z=<1> x=<3>

That makes it clear that the part of $b's value after the first token
is being treated as additional arguments to "local".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: sensible "local" support?
  2010-11-07 13:17 sensible "local" support? Jim Meyering
@ 2010-11-07 18:28 ` Jonathan Nieder
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Nieder @ 2010-11-07 18:28 UTC (permalink / raw)
  To: Jim Meyering; +Cc: dash

Jim Meyering wrote:

> Would you be open to the idea of making dash's "local" work more
> like the scope modifier that its name implies than like a separate
> command in which assignments have different semantics?
>
> To be clear, "local" is not standardized, so the change I'm advocating
> would not be a bug fix ;-)  However, it would make dash align with
> bash and zsh, and imho, with common sense.

FYI:
https://www.opengroup.org/sophocles/show_mail.tpl?source=L&listname=austin-group-l&id=14935

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-11-07 18:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-07 13:17 sensible "local" support? Jim Meyering
2010-11-07 18:28 ` Jonathan Nieder

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.