git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] shell: local x=$1 may need to quote the RHS

From
Taylor Blau <me@ttaylorr.com>
Date
Jan 25, 2022, 20:19 UTC
Message-ID
<YfBbRca0Rjl59MM0@nand.local>
In-Reply-To
<xmqqa6fjzlm0.fsf@gitster.g>
On Tue, Jan 25, 2022 at 11:00:39AM -0800, Junio C Hamano wrote:
Show 21 quoted lines
> Konstantin Khomoutov <kostix@bswap.ru> writes:
>
> > Sorry, I might have not followed the entire thread, but assignment in
> > `local` is a bashism, and dash can only handle the declaration part with
> > `local`, not assignment; hence the safe code should read
> >
> >   local x
> >   x="$1"
>
> Interesting.  As "local" is not in POSIX but we still use it for
> convenience, we must limit our use to a reasonable subset of
> features common to the shells we care about.  Knowing what each
> shell can and cannot do safely is essential to us.
>
> The patch posted seemed to run fine with a more recent dash than
> what I had trouble with (0.5.10 would work fine with "$1" quoted,
> 0.5.11 would work fine without $1, just like the RHS of a regular
> assignment).  In addition, there are many existing tests that
> already use "local var=initial-value" (the message you are
> responding to has an output from "grep") and we haven't got problem
> reports from dash users about them.

Yeah; bisecting dash with your example script pointed me at cbb71a8 (eval: Add assignment built-in support again, 2018-05-19), which indeed appears in v0.5.11 (and all subsequent versions).

cbb71a8 points at release 0.3.8-15, which predates Git (and a tag pointing at it was never created, since it's behind the big "initial import" commit at the beginning of dash.git's history). But skimming ChangeLog.O, we see:

    * Removed assignment builtins since it is at best undefined by the
      SuS and also can't be implemented consistently.
So this probably didn't work at all between that 0.3.8-15 up until v0.5.11.
> The manual page for recent dash may need an update.
> Can you perhaps file a bug on their documentation?

Yes, I agree that dash.1 is out-of-date after cbb71a8. Konstantin: please feel free to use any of this if it's helpful to you in creating a bug report for the dash folks.

Thanks, Taylor

Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 9 in “[RFC] shell: local x=$1 may need to quote the RHS”
  1. Junio C HamanoJan 24, 2022
  2. Konstantin KhomoutovJan 25, 2022
  3. Junio C HamanoJan 25, 2022
  4. Taylor BlauJan 25, 2022
  5. Junio C HamanoJan 26, 2022
  6. Konstantin KhomoutovJan 26, 2022
  7. SZEDER GáborJan 26, 2022
  8. Taylor BlauJan 26, 2022
  9. Junio C HamanoJan 27, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.