[Toybox] echo --help

Rob Landley rob at landley.net
Wed Oct 8 13:11:08 PDT 2025


On 10/7/25 13:22, enh wrote:
> On Tue, Oct 7, 2025 at 1:45 PM Rob Landley <rob at landley.net> wrote:
>>
>> In bash, "echo --help" prints "--help". In /bin/bash it dumps help text.

/bin/echo I mean.

 > yeah, "if you're not using -- you're already doing it wrong" sgtm.

Except for:

$ busybox echo -- hello
-- hello
$ bash -c 'echo -- hello'
-- hello
$ /bin/echo -- hello
-- hello

I'm serious that toybox _uniquely_ parses "--" in echo.

Meanwhile, "busybox echo --help" also prints "--help", as do the dash 
and mksh echo builtins. (I was kinda surprised they have them too, but 
both the behavior differing from the echo in the $PATH and "strace |& 
grep fork" for both dash and mksh not finding one say it's builtins.)

That's 4 votes out of 5, with the only outlier being a gnu 
implementation that basically never gets used even on gnu systems...

$ /usr/bin/[ --help
Usage: test EXPRESSION
   or:  test
   or:  [ EXPRESSION ]
   or:  [ ]
   or:  [ OPTION
Exit with the status determined by EXPRESSION.

Oh yeah, they got "test" wrong too. That's gnu/borked. I'm leaning 
towards NOHELP now.

Hmmm... The echo argument parsing is already complicated, using 
prefix-only logic and the "wait, we didn't understand that so back up 
and keep it" logic ala:

$ toybox echo --credenza
--credenza
$ toybox echo -nx
-nx
$ toybox echo a --
a --

And I already taught the plumbing that "stop at the first nonoption 
argument" applies to --help and --version too:

$ toybox echo --help walrus
usage: echo [-Een] [ARG...]
...
$ toybox echo walrus --help
walrus --help

Which, to be honest, should probably ALWAYS be the case. (I'm aware that 
gnu "ls -l potato --help" prints the help text and does not try to look 
for a file called potato, and yes I copied that behavior in toybox, and 
now I'm going... yeah gnu is nuts here.)

I could make it so --help or --version activating requires the rest of 
the command line to be _empty_. Which is probably good in general, 
because this is just gnu/wrong:

   $ touch file
   $ rm -rf file --help >/dev/null
   $ ls file
   file
   $ rm file -i
   rm: remove regular empty file 'file'?

Yeah... not liking that at all.

   $ :|rm file -i
   rm: remove regular empty file 'file'? $ ls file
   file

Doesn't even print a newline for EOF, and defaults to no. Bra fscking 
vo. (But grandfathered in...)

Ahem. Behavior of "echo".

Consistent behavior would say that if "echo --help" with no other 
arguments prints help then "test --help" with no other arguments should 
also print the help... which sounds like a security flaw waiting to 
happen, which says echo should probably be NOHELP. (As with all such 
commands, "help echo" and "toybox --help echo" should still work, and 
it's in https://landley.net/toybox/help.html#help .)

Sigh, it's another one of those "the fighting is so vicious because the 
stakes are so small" things. Parsing -- but not --help is silly, I can't 
STOP parsing -- because stuff is using it (and the argument about being 
able to echo just "-e" remains relevant), but test --help shouldn't (no 
matter what gnu's $PATH implementation says)...

Alright, --help and --version should take effect when they are the first 
and ONLY argument to a command, except for toybox --help command which 
is an existing special case. And NOHELP suppresses that first argument 
because "true" should still never produce output (or error on stdout 
refusing to accept data).

Rob

P.S. It's pre-release polishing, the traditional time to give the todo 
list a quick scrub to see what comes out.


More information about the Toybox mailing list