[Toybox] Thoughts on seperating shell dependencies and MAYFORK commands?

Mouse mouse at Rodents-Montreal.ORG
Wed Feb 21 06:29:29 PST 2024


I'm not a routine toybox user.  But, to the extent that toybox tries to
be general-purpose, perhaps some comments from general-purpose shell
use are relevant here.

> There used to be a blog that handed out the "unnecessary use of cat"
> award, because redirects are cheaper.

When they work.  I never investigated enough to be in a position to say
anything definite, but I've seen occasional (emphasis on "occasional")
cases where cat THING | ... works, but < THING ... doesn't.  Maybe all
such cases represent bugs?  Not sure.

> I _could_ also have the shell special case recognize "cat singlefile
> |" as an input redirect,

Hm, personally, I don't like that.  Even if we postulate that all the
above cases where cat works but redirection doesn't represent bugs, I
don't like tools that silently rewrite what I told them to do into
something else they happen to think is equivalent, because it isn't
always.  (As a simple example, I may be planning to SIGSTOP the cat to
freeze input at some point; depending on what it's being piped into, it
may not be suitable to stop that instead.)

> But "sed 'pattern' long list of input files" is gonna be faster than
> "for i in long list of input files; do sed $i; done" even if the
> shell overhead was literally free, because of the repeated setup code
> in both OS and the command.

...again, when both work.  I've done the latter (or more often
something with xargs) in some cases where the list is so long the
former would overflow the max arglist size.  I've also (though less
often) had cases where I don't want to wait for the whole list to be
computed before getting working on the first few items.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse at rodents-montreal.org
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


More information about the Toybox mailing list