Bugs in defconfig /bin/sh

Denys Vlasenko vda.linux at googlemail.com
Sun Oct 3 12:49:03 UTC 2010


On Sunday 03 October 2010 02:35, Rob Landley wrote:
> On Thursday 30 September 2010 17:15:44 Denys Vlasenko wrote:
> > On Thursday 30 September 2010 23:29, Rob Landley wrote:
> > > > > (Making {file,file} curly bracket support work would be darn nice
> > > > > too, that's the biggest thing I miss.  You can't even follow the
> > > > > Linux From Scratch build instructions without that...)
> > > >
> > > > This is not easy. Consider three commands:
> > > >
> > > > v='/bin/*'; echo $v
> > > > v='/bin/{a,b}*'; echo $v
> > > > echo /bin/{a,b}*
> > > >
> > > > In the first case, unquoted $v is globbed *after* $v value is
> > > > substituted, and echo prints long list of filenames in /bin.
> > > >
> > > > In the second case, echo prints just "/bin/{a,b}*"
> > > >
> > > > In the third case, echo prints all filenames in /bin which start from a
> > > > and b.


> Wildcards can be inside the curly brackets as easily as outside:
> 
>   blah/{o?e,two.*}/*.txt

For brace expansion, glob chars have no special meaning.
It simply expands to:

blah/o?e/*.txt blah/two.*/*.txt

and then both words are globbed.


> So either resolution happens at the same time, or you make multiple resolution 
> passes in which case keeping track of what was quoted and what wasn't (and 
> what was already expanded and what wasn't) is INSANE.

It is already rather complex, with nested "...", $(cmd), `cmd`, ${var/pattern/repl}
and so on. With backspace quoting on every level (with subtly different rules!).
I'd say we are already in "insane" land.


> > if we want to have more users,
> 
> More than we have right now, when we don't support {} at _all_ even in the 
> trivial completely unquoted cases with no wildcards present?
> 
> If we want more users, then we need to run their scripts.  Don't worry about 
> what bash does or doesn't do in made-up examples, show me scripts people are 
> currently using which don't run under hush.  And the only way to do that is 
> approximate bash's behavior closely enough that people _try_ to run those 
> scripts, meaning adding trivial {} support and then seeing where it's 
> insufficient and needs to be expanded.
> 
> > we should be compatible with bash (latest one, if older ones
> > are different).
> 
> You're suggesting a need to be bug-for-bug compatible with something that 
> changes its behavior every version.  That's not a viable course of action.

Rob, this is not a bug. Example of bugs:

for v in     ""; do echo "v=$v"; done  # prints "v=". ok
for v in "$@"""; do echo "v=$v"; done  # doesnt print anything!

export   a=`echo b c`  # exports a='b c'
"export" a=`echo b c`  # not the same as above!

We do not have to implement bash behavior for insane cases like these.

But v='/bin/{a,b}*'; echo $v isn't a too far-fetched thing like above ones.
Users WILL try something like it, and ask it to be fixed.

Brace expansion and globbing are documented to be two different things.

Implementing them incorrectly will force me later to rip them out,
and reimplement correctly again. This already happened in ash's
${var/pattern/repl} code. It is broken now. "Simply" fixing it
is not possible, it needs to be redone from scratch.

I do not want to write the same thing twice.


> I note that dash still doesn't handle {} at all, and thus can't be used to run 
> this bit of LFS:
> 
>   http://www.linuxfromscratch.org/lfs/view/6.7/chapter06/creatingdirs.html
> 
> Now LFS gets away with that because they build bash in chapter 5, so they know 
> what they're running with.  But I make my own chapter 5 equivalent out of an 
> Aboriginal Linux root filesystem and I need to build bash 2.05b to get it to 
> work.  I cannot use hush for that case, because of the lack of trivial {} 
> support.  Not because of some "quoted string stuck in a variable then gets 
> expanded in a way that changes the precedence of braces vs wildcards" corner 
> case bug, but because the basic functionality isn't htere.

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 dread to think what corner cases with escaped \{ and unpaired {}s
I will need to chase down now...

Please try current git.

-- 
vda


More information about the busybox mailing list