Subject: Re: bug#47859: Additional seq outlandish example: seq 0 dangers

From: Bernhard Voelker <[email-masked]>
Date: Mon, 19 Apr 2021 08:23:41 +0200

On 4/18/21 3:26 AM, 積丹尼 Dan Jacobson wrote:
> Here's another 'fun/sad/DDOS yourself' example you might add:
> 
> One day I wrote a Makefile,
> m:
> 	seq 0 9|sed s/$$/號.html/|xargs make
> but before using it, I though I'll just test with one item,
> m:
> 	seq 0  |sed s/$$/號.html/|xargs make
> well of course... as seq prints nothing here,
> this triggered a massive ever growing recursive loop...
> 
> Yes, all my fault for picking 0. I'll pick 1 next time.

Besides the main discussion about seq(1), I want to add that xargs(1) [0]
is often run most usefully with:

  -r, --no-run-if-empty        if there are no arguments, then do not run COMMAND;
                                 if this option is not given, COMMAND will be
                                 run at least once

Portability hint:
Unfortunately, the -r option is not required by POSIX.  At least, the BSD family
(FreeBSD [1], NetBSD [2], OpenBSD [3]) has it; on Solaris [4], only the '1g'
variant [5] has it.  Not sure about other implementations.

[0] https://www.gnu.org/software/findutils/manual/html_node/find_html/xargs-options.html
[1] https://www.freebsd.org/cgi/man.cgi?xargs
[2] https://man.netbsd.org/xargs.1
[3] https://man.openbsd.org/xargs.1
[4] https://docs.oracle.com/cd/E88353_01/html/E37839/xargs-1.html
[5] https://docs.oracle.com/cd/E88353_01/html/E37839/xargs-1g.html

Have a nice day,
Berny