Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Bug report: Strange behaviour with random, sort and uniq
- X-seq: zsh-workers 51479
- From: Sheogorath <zsh@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Bug report: Strange behaviour with random, sort and uniq
- Date: Sat, 25 Feb 2023 23:02:55 +0000
- Archived-at: <https://zsh.org/workers/51479>
- Feedback-id: 1.eu-central-1.xpHyXi0Gn6udT8dq66O1NgFCpD0sp/inS5fRAuWSdFQ=:AmazonSES
- List-id: <zsh-workers.zsh.org>
Hello ZSH maintainers,
I found a quite strange bug in my current installation. I tried to do
some virtual dice flips and something strange appeared.
I was running the following command in a terminal:
for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done | sort | uniq
-c
When run twice after each other, it produces the same output:
Example:
$ for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done | sort |
uniq -c
12 1
17 2
22 3
19 4
16 5
15 6
$ for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done | sort |
uniq -c
12 1
17 2
22 3
19 4
16 5
15 6
However, this changes, as soon as one run the command without the 'sort
| uniq -c' piping:
for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done
Next time, the output of 'for i in $(seq 0 100); do echo $((1 + RANDOM
% 6)); done | sort | uniq -c' will be different.
When redirecting the output of the command into files, these are also
different.
Since all of this was so strange, I reproduced it on Fedora 36 in a
container (using zsh -f) as well as on my Fedora 37 host. Also in a VM,
with a fresh Fedora 37 install on Hetzner and a Debian 10 install, to
make sure, it's not due to a distro specific modification.
I also validated, that this behaviour doesn't exist in bash.
I hope you'll have fun debugging it, I have no idea where to even
start.
Greetings
Sheogorath
Messages sorted by:
Reverse Date,
Date,
Thread,
Author