[patch] Not quite bbsh. :)
Rob Landley
rob at landley.net
Fri Sep 1 21:20:45 UTC 2006
So here's a little toy I made; the world's most pathetic shell. It's an
experiment to see how small I can get a shell down to, and it does indeed
beat lash in both size and lameness.
To be clear, this is _not_ bbsh, this is just more research for bbsh to figure
out how little I can get away with. Eventually I'm thinking bbsh with all
optional features disabled should give you something about like this, only
probably doing some kind of bounds checking when assembling argv[] (or just
breaking down and using xrealloc()), and maybe recording the return codes of
the commands it runs, and an error message when cd fails would be nice...
Anyway, I think this is as minimal as a shell gets. It's just a dumb little
loop: read a command, run the command, repeat. It doesn't do terminal
control, it doesn't handle pipes/redirection/semicolons, it doesn't
understand environment variables, it doesn't do quoting, there's no job
control... Even things _that_ basic are going to be config options in bbsh.
Anyway, people were asking for a progress report, and unlike the reams of
notes and various code snippets I've collected in a heap (plus the enormous
to-read pile I'm churning through), this example actually runs. :)
Rob
P.S. Right now the question I'm wrestling with in this context is "what
constitutes good NOMMU support"? I could trivially have xrealloc()ed argv[],
but didn't because allocations fragment memory on a nommu system. This means
I want at least the option to use a preallocated buffer for the input line,
the parsed data each argv[] element points to, and argv[] itself. All of
that implies size limitations, so systems with mmu shouldn't have to put up
with it, but I don't want large differences in the code paths if I can help
it.
P.P.S. Making terminal control work with vfork() is one of those things that
makes your head hurt and will require extensive experimentation. Possibly
clone() is better, I have a whole bunch of todo items here which are in the
form of unanswered questions...
P.P.P.S. Yes I can easily replace the four lines after the "grab next word"
comment with a function call to parse the next argument and fill out argv,
and plug in all the quoting and globbing and environment variable expansion
stuff there, except that it's not _quite_ that simple because one argument
can expand to more than one argv, ala "${woot[@]}" or "/usr/bin/{busybox,ls}"
and I have to figure out whether I understand all the implications of that.
Rob
--
Never bet against the cheap plastic solution.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bbsh.diff
Type: text/x-diff
Size: 3258 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20060901/9ba9a391/attachment-0002.bin
More information about the busybox
mailing list