[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#13525: 8.20 - [seq 1 3 1] treated as [seq 1 3]
From: |
Bernhard Voelker |
Subject: |
bug#13525: 8.20 - [seq 1 3 1] treated as [seq 1 3] |
Date: |
Tue, 22 Jan 2013 14:47:01 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 |
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