git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Khomoutov <kostix@bswap.ru>
To: Junio C Hamano <gitster@pobox.com>
Cc: Taylor Blau <me@ttaylorr.com>,
	Konstantin Khomoutov <kostix@bswap.ru>,
	git@vger.kernel.org
Subject: Re: [RFC] shell: local x=$1 may need to quote the RHS
Date: Wed, 26 Jan 2022 14:39:39 +0300	[thread overview]
Message-ID: <20220126113939.cl5pbcous4gmdjri@carbon> (raw)
In-Reply-To: <xmqqo83zt54a.fsf@gitster.g>

On Tue, Jan 25, 2022 at 09:53:25PM -0800, Junio C Hamano wrote:

> Taylor Blau <me@ttaylorr.com> writes:
> 
>> 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.
[...]
> So here is a bit wider "grep" output, looking for
> 
> $ git grep '^[ 	]*local[	 ].*=' \*.sh
> 
> to reject _any_ assignment on the same line as "local", but I
> manually excluded the ones that are not meant to be run with dash.
> I obviously excluded the one in t0000 (try_local_xy) that is a
> weather-balloon for this exact issue.
> 
> According to this thread, these would not work correctly on dash
> older than 0.5.11 and needs fixing by splitting declaration of
> variables as locals and assignment of their initial values.

By the way, back then when Debian and Ubuntu were switching running their
system scripts from bash to dash (which bought definite speedups), many
scripts had to get rid of bashisms, and this page [1] summarizes quite many
differences between these shells including handing of `local`.
To cite it:

| Dash (old versions maybe?) and (at least) bash do not handle local the same:
|
| -    local a=5 b=6;
| +    local a=5;
| +    local b=6;
|
| The first line in /bin/bash makes a and b local variables. And in /bin/dash
| this line makes b a global variable! 

Not sure it lists a possible problems our test harness also has but wanted to
give a heads-up anyway just in case.

 1. https://wiki.ubuntu.com/DashAsBinSh


  reply	other threads:[~2022-01-26 11:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 20:11 [RFC] shell: local x=$1 may need to quote the RHS Junio C Hamano
2022-01-25  9:24 ` Konstantin Khomoutov
2022-01-25 19:00   ` Junio C Hamano
2022-01-25 20:19     ` Taylor Blau
2022-01-26  5:53       ` Junio C Hamano
2022-01-26 11:39         ` Konstantin Khomoutov [this message]
2022-01-26 21:48         ` SZEDER Gábor
2022-01-26 21:52         ` Taylor Blau
2022-01-27  0:17           ` Junio C Hamano

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=20220126113939.cl5pbcous4gmdjri@carbon \
    --to=kostix@bswap.ru \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.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;
as well as URLs for NNTP newsgroup(s).