Subject: Re: bug#13525: 8.20 - [seq 1 3 1] treated as [seq 1 3]

From: Bernhard Voelker <[email-masked]>
Date: Tue, 22 Jan 2013 14:47:01 +0100

On 01/22/2013 02:24 PM, Pádraig Brady wrote:
> Yes I was wondering that myself.
> 
> Though I suppose that `seq 0 0 1` prints endlessly,
> means that it's consistent that as long as start <= end
> and step == 0, then start is printed endlessly.

Yes, from a mathematical point of view, seq is right.
Therefore, maybe documenting seq's behavior would suffice.
OTOH ...

> Maybe we should special case to only print
> the start value once if step = 0.

... users may not be amused about an endless loop in a tool
which is otherwise meant for counting, e.g.

  $ seq $start $step $last | \
  while read x ; do work_on $s ; done

Stopping after the start valie is maybe not mathematically
correct, but more "natural".

> Maybe one could use a step of 0 to hack a
> min/max function or something?
>
>    min() { minv=$(seq "$1" 0 "$2"); : ${minv:="$2"}; echo $minv; }
>    max() { minv=$(seq "$1" 0 "$2"); : ${maxv:="$1"}; echo $maxv; }

TBH this doesn't look like as if a normal user would be
able to invent this. ;-)

Have a nice day,
Berny