GNU bug report logs - #49217
'shuf' returns nothing if the low range number is higher by 1 than the high number

Previous Next

Package: coreutils;

Reported by: F8ER F8ER <the.f8er <at> gmail.com>

Date: Fri, 25 Jun 2021 04:14:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #28 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Erik Auerswald <auerswal <at> unix-ag.uni-kl.de>, bug-coreutils <at> gnu.org,
 49217 <at> debbugs.gnu.org, the.f8er <at> gmail.com
Subject: Re: bug#49217: 'shuf' returns nothing if the low range number is
 higher by 1 than the high number
Date: Fri, 25 Jun 2021 09:29:04 -0700
On 6/24/21 11:49 PM, Erik Auerswald wrote:
>      $ shuf -i 2-0 ; echo %exit code $?
>      shuf: invalid input range: ‘2-0’
>      %exit code 1
>      $ shuf -i 1-0 ; echo %exit code $?
>      %exit code 0
> 
> This looks inconsistent and possibly not exactly as intended.

It's exactly what I intended and there's no inconsistency. When you say 
'shuf -i M-N' you select from a collection of N-M+1 lines. N-M+1 = 0 (no 
input lines) makes sense, but N-M+1 < 0 (negative number of input 
lines?) does not.

> I'd like to
 document it and add test cases.

Feel free, though we need to reserve the right to extend 'shuf' in the 
future. In other words, not every invocation of 'shuf' that provokes a 
diagnostic now will provoke a diagnostic in the future.




This bug report was last modified 3 years and 326 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.