RFC: 3 shells (ash, dash, bash), 3 different behaviours

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Thu Mar 20 22:18:11 UTC 2014


On Thu, 20 Mar 2014, Denys Vlasenko wrote:
> On Wed, Mar 19, 2014 at 6:47 PM, Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com> wrote:
> > On Mon, 17 Mar 2014, Cristian Ionescu-Idbohrn wrote:
> >>
> >> I just had a look att commit 109ee5d33694a03cda3424b4846584250832ba8e.
> >> IMO, to imitate bash behaviour isn't the right thing to do.  It's a bug.
>
> It is also the most widely used shell in Linux.

That does not imply bug-free.

> >> Imitate dash behaviour instead.
>
> Why? Bash user base is much larger than dash, and likely
> to remain to be, unless dash developers stop being stubborn
> and implement at least, say, command-line editing. Right now,
> they seem to enjoy torturing their users. Not a good attitude.

That's a biased optinion, IMO.

> > I can now confirm the commit breaks several scripts based on these
> > assumptions:
> >
> > 1. all script variables are global...
> > 2. ...unless declared local
> > 3. a `local' declaration inherits the upper scope variable value
>
> About (3): Says who?

Common sense?

> > 4. `local' modifications of the variable value are thrown away upon
> >    `return' from the function
> >
> > I consider the bash behaviour buggy.
>
> Considering that sane usage of "local" is to make sure that
> locally-used variables don't trash global variables' values,
> both behaviors are okay in practice.

In practice, it won't make too much a difference.

* knowlegeable bash users would assume a `local' declared variable
  would `unset' unset variable, and they will reset it
* dash users will assume a `local' declared variable is inherited
* both win

> > Several distributions (besides debian) adopted, for several reasons,
> > dash as the system shell.  Using shell script code from such
> > distributions and running it under busybox ash will break.
>
> Did you find a real-world script which does depend on
> previous value of "local" variable? Please show it.

Alright.  See attached.
Run it with:

	$ dash /path/to/foo.sh
	$ bash /path/to/foo.sh
	$ /path/to/busybox ash /path/to/foo.sh


Cheers,

-- 
Cristian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.sh
Type: application/x-sh
Size: 597 bytes
Desc: 
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20140320/5ddf0487/attachment.sh>


More information about the busybox mailing list