"Useless Use of Cat Award" [0] is the canonical text for avoiding unnecessary use of cat, for those who haven't come across it yet.
[0] http://porkmail.org/era/unix/award.html (2000)
"Useless Use of Cat Award" [0] is the canonical text for avoiding unnecessary use of cat, for those who haven't come across it yet.
[0] http://porkmail.org/era/unix/award.html (2000)
cat file | this | that | other | out
vs
this < file | that | other | out
In the cat example, it's easy to change the head of the pipeline, by adding things before "this" or deleting "this", which is less so in the non-cat example. (The use case I have in mind is experimental commands that take probably <10s to complete, where editing time is a significant fraction of the time you spend.) < file this | that | other | outMaybe there are cases where a long string of awk|something|other|sort|uniq is not the problem, but forking an extra process for cat is.
And maybe there's a mismatch between pipes, files and mmap today. Splice seems like a reasonable fix (if we splice all the things, awk, grep etc).
Finally, I just think:
cat input.txt \
| filter1 args \
| filter2 args \
| reduction \
| ouput-formater
Reads better than having to tack on an <input.txt at the end, or special-case the first filter to be (... And also open a file). < input.txt filter1 args # ... rest of pipeline
(But I agree that the cat version is more readable.)I'd say that is somewhat of a harsh premise, especially since the in-place editing of files available e.g. in many GNU tools (awk, sed, sort) is really useful and based on exactly that possibility.
I do agree that cat often makes pipes easier to read, though. And yes, obsessing over that one additional process seems to be somewhat silly. Unless, of course, it introduces a real bottleneck and the whole thing is time sensitive.
With `cat`, a new process must be created. But with shell redirection, no new process is necessarily created, so that is going to be faster.