bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Erik Auerswald
Subject: bug#47859: Additional seq outlandish example: seq 0 dangers
Date: Sun, 18 Apr 2021 08:29:59 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Sun, Apr 18, 2021 at 09:26:28AM +0800, 積丹尼 Dan Jacobson wrote:
> On (info "(coreutils) seq invocation") we read
>    Be careful when using ‘seq’ with outlandish values: otherwise you
>    may...
> 
> 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.
> 
> P.S., perhaps document how to get seq to cough up just "0". One way I
> found was:
> $ seq 0 1 0
> 0

I would like to add more information to this bug report with the intent of
helping everybody involved now or in the future.

A slighly simpler method to make 'seq' print just '0' is:

    $ seq 0 0
    0

This is documented, but more generally, e.g., in 'seq --help':

    $ seq --help
    Usage: seq [OPTION]... LAST
      or:  seq [OPTION]... FIRST LAST
      or:  seq [OPTION]... FIRST INCREMENT LAST
    Print numbers from FIRST to LAST, in steps of INCREMENT.
    [...]
    If FIRST or INCREMENT is omitted, it defaults to 1.  [...]
    [...]

Thus, 'seq 0' is the same as 'seq 1 1 0' and 'seq 0 0' is the same as
'seq 0 1 0'.

The default value of '1' for omitted parameters affects other values, too,
not just '0':

    $ seq -1
    $ seq -1 -1
    -1
    $ seq -100000
    $ seq -100000 -100000
    -100000

When "FIRST" and "LAST" are the same, any valid "INCREMENT" value results
in 'seq' printing just one value, not just the default of '1':

    $ seq 0 200 0
    0
    $ seq 0 -200 0
    0
    $ seq 0 0 0
    seq: invalid Zero increment value: ‘0’
    Try 'seq --help' for more information.

Thus IMHO a possible addition to the documentation should probably not
just single out 'seq 0', but mention any number smaller than the default
value for "FIRST" of '1'.

HTH, HAND
Erik
-- 
Inside every large problem is a small problem struggling to get out.
                        -- Hoare's Law of Large Problems





reply via email to

[Prev in Thread] Current Thread [Next in Thread]