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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

> Taylor Blau <me@xxxxxxxxxxxx> 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux