mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-20 18:56:39 +02:00
shuf: fix bug with ‘-r -n 0’
‘shuf -r -n 0 file’ would mistakenly read from standard input. Problem reported by my student Jingnong Qu while reimplementing a shuf subset in Python as an exercise in UCLA Computer Science 35L: https://web.cs.ucla.edu/classes/fall19/cs35L/assign/assign3.html * NEWS: Mention the fix. Also, ASCIIfy a previous item. * src/shuf.c (main): Fix bug. * tests/misc/shuf.sh: Add a test case for the bug.
This commit is contained in:
@@ -39,6 +39,10 @@ compare in out > /dev/null && { fail=1; echo "not random?" 1>&2; }
|
||||
sort -n out > out1
|
||||
compare in out1 || { fail=1; echo "not a permutation" 1>&2; }
|
||||
|
||||
# Exercize shuf's -r -n 0 options, with no standard input.
|
||||
shuf -r -n 0 in <&- >out || fail=1
|
||||
compare /dev/null out || fail=1
|
||||
|
||||
# Exercise shuf's -e option.
|
||||
t=$(shuf -e a b c d e | sort | fmt)
|
||||
test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; }
|
||||
|
||||
Reference in New Issue
Block a user