Bugs in defconfig /bin/sh

Denys Vlasenko vda.linux at googlemail.com
Sun Oct 3 21:45:32 UTC 2010


On Sunday 03 October 2010 22:54, Rob Landley wrote:
> > Rob, this is not a bug. Example of bugs:
> 
> It's inconsistent, the spec doesn't say what the correct behavior is, and the 
> behavior changes from version to version.
> 
> > for v in     ""; do echo "v=$v"; done  # prints "v=". ok
> > for v in "$@"""; do echo "v=$v"; done  # doesnt print anything!
> 
> How is that a bug?  That's normal quote processing.
> 
> Just as "a""b" is combined together into the single argument "ab", "${@}""x" 
> would be combined together into "${@}x", so "$@""" is combined together into 
> "$@" which is then expanded normally, and in the case of no command line 
> arguments expands into zero arguments.

Nothing says that "abc""def" is the same as "abcdef".

I find it extremely puzzling that "" is a word (not nothing),
but ADDING something to it ("$@") can annihilate it!

This applieds not only to explicit "", but to quoted expansion
of variables with empty values, empty command substitutions
like "`echo`" and such:

set --
a='a'
for v in "$@""$a"; do echo "v=$v"; done  # prints "v=a"
for v in "`echo`"; do echo "v=$v"; done  # prints "v="
a=''
for v in "$@""$a"; do echo "v=$v"; done  # doesn't print anything?!
for v in "$@""`echo`"; do echo "v=$v"; done  # doesn't print anything?!

In my opinion, these should print nothing:

a=''
for v in "$@"$a; do echo "v=$v"; done
for v in "$@"; do echo "v=$v"; done

But these should print "v=":

a=''
for v in "$@""$a"; do echo "v=$v"; done
for v in "$@"""; do echo "v=$v"; done

This just makes more sense regarding usual rules of expansion
of quoted and unquoted strings: quoted string never vanish
unless it's "$@", while unquoted one can vanish.

The fun part is that hush _does_ match bash here - just because
this quirky/buggy behaviour is easier to code.
It "comes out natually".
I guess bash does this for the same reason.


> > I believe I implemented brace expansion in hush so that it passes
> > all three these tests:
> >
> > v='/bin/*'; echo $v
> > v='/bin/{a,b}*'; echo $v
> > echo /bin/{a,b}*
> 
> I guess I should go report the inconsistent behavior to the bash people now, 
> and let them evaluate the inconsistency.  They might fix it in the next 
> version, in which case you can claim you're compatible with older versions of 
> bash but not the current one.

Well, I'd like you to try current git's hush :D

-- 
vda


More information about the busybox mailing list