GNU bug report logs - #61267
shuf -i with negative numbers

Previous Next

Package: coreutils;

Reported by: <kpm <at> plan9.lol>

Date: Sat, 4 Feb 2023 07:46:02 UTC

Severity: normal

Tags: notabug

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


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

From: Pádraig Brady <P <at> draigBrady.com>
To: kpm <at> plan9.lol, 61267 <at> debbugs.gnu.org
Subject: Re: bug#61267: shuf -i with negative numbers
Date: Sat, 4 Feb 2023 12:09:25 +0000
tag 61267 notabug
close 61267
stop

comments below...

On 03/02/2023 22:31, kpm <at> plan9.lol wrote:
> hello
> 
> shuf -i option cannot handle negative numbers.
> examples:
>    $ shuf -i -10-20
>    $ shuf -i 0--20
> 
> don't know if it's a bug or a feature.

The input range needs to be unsigned
as documented in the info manual.
It should be easy enough to shift to the desired range,
for example:

  $ shiftn() { sed "s/\$/$1/" | bc; }
  $ shuf -i 0-10 | shiftn -5
  3
  -2
  0
  5
  2
  -5
  4
  -1
  -3
  1
  -4

cheers,
Pádraig




This bug report was last modified 2 years and 169 days ago.

Previous Next


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