[BusyBox] For...do...done...

Larry Doolittle ldoolitt at recycle.lbl.gov
Tue May 22 10:12:11 UTC 2001


I claimed:

> If you want to [try writing for..do..done support for hush]
> yourself, the general support is in there,
> you would only need to add some case to run_list_real().
> The parsing is already taken care of in reserved_word(),

Well, that's half true.  I see now that some major surgery
to the hush parser will be required before a for loop can
be _usefully_ processed.

The current parser expands variables too early.  So if someone
hacked up reserved word(), they would get behavior like:

$ f=foo
$ for f in a b c; do echo $f; done
foo
foo
foo
$ 

Not exactly the intended effect.  The current parsing strategy
falls down in a couple of other (less bothersome) cases, too:

echo "echo Hello World" >"a=b"
unset a
chmod a+x "a=b"
PATH=$PATH:.
"a=b"
echo $a

ash/bash treats "a=b" as a command, and echos "Hello World" at that point.
Hush thinks it's a variable assignment, and echos "b" on the following line.

rm -f foo
TMP=foo && >$TMP
ls foo

Besides the fact the the CVS copy core-dumps on the "TMP=foo && >$TMP"
line, the current generation of hush parser expands $TMP too soon, and
will attempt to create a blank file (that's probably why it crashes).
Both ash and bash will correctly create foo.

Hush is still an interesting and useful shell, and vastly more capable
than lash.  I'd like to see some more bugs cleaned up, inefficiencies
trimmed down, and features added (e.g., signal handling).  I wanted to
point out its defects, before someone gets the idea it will handle full
Bourne syntax (e.g., for, alias, case, function, here-documents) correctly
anytime soon.  I will study the substitution sequence issue, and see if
I can fix it without rewriting the whole program.  Either way, it will
presumably be at least a month before I come up with any useful code.
As always, ambitious programmers who would like an educational project
are welcome to beat me to it.  You'd better know what you're doing, though,
or you'll make a mess of it.  :-)

      - Larry

P.S.  I find hush works much better if I change all the exit() calls
in pseudo_exec() to _exit().  I mailed a patch to Erik, but he hasn't
applied it yet.





More information about the busybox mailing list