by masklinn · 9y ago · 0 comments
cat /dev/zero|pv >/dev/null
gives me roughly 2/3 the speed of yes. (5 GB/s vs 7 GB/s) Plus yes gives you an arbitrary string, instead of only zeroes.but here's todays Useless Use of Cat Award http://porkmail.org/era/unix/award.html
https://news.ycombinator.com/item?id=14414610
But in that case one could probably say that Gnu awk is just not very good at input handling (as Mawk doesn't appear to benefit from an extra "cat").
pv > /dev/null < /dev/zero </dev/zero pv >/dev/nullpv </dev/zero >/dev/null
which is a common way of doing it (for any command with any inputs and outputs, not just the above ones), i.e.:
command < input_source > output_dest
All three pv command invocation variants, the one here and the two above, work. And it becomes more clear why they are the same, when you know that the redirections are done by the shell + kernel, and the command (such as pv) does not even know about it. So in all three cases, it does not see the redirections, because they are already done by the time the command starts running (with its stdin and stdout redirected to / from those respective sources). And that is precisely why the command works the same whether it is reading from the keyboard or a file or pipe, and whether it is writing to the screen or a file or pipe.
[edit] That's actually inaccurate (and badly expressed), see comments below.