[Toybox] is orthodoxy a strong value of toybox?
Rob Landley
rob at landley.net
Thu Sep 1 10:24:05 PDT 2022
On 9/1/22 05:25, Marc Chantreux wrote:
> hello people,
>
> This is my first post so:
>
> * Rob (and maybe other contributors I don't know about): thank you so much for your work
> * short intro of myself: I work at the University of Strasbourg HPC,
> linux user since the last millenium (always happy to help and share),
> perl monger and raku early adopter.
>
> I would like to challenge toybox as the standard shell scripting environment
> for some projects at work as:
> * we need something to be officially supported
> * we fear GNU tools (both bash and coreutils)
> * 9base and sbase are niche
> * I saw a great talk about busybox vs toybox
>
> So here I am. What I did for the moment is:
>
> make menuconfig
> make
> set $(realpath ./toybox) ~/local/bin
> mkdir -p $2/t
> $1 | tr ' ' '\n' | xargs -IT ln -s $1 $2/t/T
> <<. install -m700 /dev/stdin ~/local/bin/toys
> #! /bin/sh
> PATH=$2:\$(getconf PATH)
> exec $1 sh "\$@"
>
> * thanks to zsh pathdirs, I can type t/sed to refer to toybox's sed.
> * I have this `toys` shell to test complete scripts
>
> Rob said toybox will be nothing more, nothing less but an implementation
> of the POSIX standard (and I understand why)
No, it'll be what the Linux command line needs. Posix is insufficient, it
doesn't even have a "mount" command. It describes a "pax" command Linux has
never used (we did "tar" instead, and it produces binary-identical output to
gnu/tar including sparse file support and xattrs).
The https://landley.net/toybox/about.html and
https://landley.net/toybox/roadmap.html pages try to explain the reasoning, but
to be honest what should and should not be included is a sadly a big judgement
call beyond a few ground rules.
Lots of the command source comments have a "deviations from posix" section. You
mentioned sed, here's that command's section:
https://github.com/landley/toybox/blob/master/toys/posix/sed.c#L14
> which defines a function
> definition as
>
> fname () compound-command
>
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_05
>
> when a lot of shells (even dash) accept
>
> fname () command(compound or not)
Bash does not accept non-compound commands, and toysh is using "what bash does"
as its standard. On debian:
$ x() echo hello;
bash: syntax error near unexpected token `echo'
> <<\. toys
> for shell in zsh dash mksh oksh 'busybox sh' yash toys; do
> $shell -c "f() echo $shell does; f"
> done
So you tried everything _except_ bash.
> zsh does
> dash does
> mksh does
> oksh does
> busybox sh does
> yash -c:1: syntax error: a function body must be a compound command
> sh: toys: No such file or directory
>
> If I want that feature, I need a first external dependency (i'll
> probably choose rc or [om]ksh) but is orthodoxy a strong value of toybox?
I don't know what you mean by orthodoxy in this context. It's not hard to add, I
literally didn't because bash didn't. No deeper reason.
> In another words: if I provide a patch to accept this grammar:
>
> fname () command
>
> Is there a chance for it to be merged ?
Hey Chet: why doesn't bash accept non-compound commands as functions? I have
wondered. Apparently other shells disagree on this...?
Rob
More information about the Toybox
mailing list