3 ms·
Many examples of "useless uses of cat" are useful IMO because they improve clarity. cat some.file | a_process | another_process > output.file is clearer tha
by dspillett 6y ago
Many examples of "useless uses of cat" are useful IMO because they improve clarity.
cat some.file | a_process | another_process > output.file
is clearer than
a_process < some.file | another process > output.file
IMO because it maintains a simple left-to-right flow. I can mentally translate between the two without thinking about it, as no doubt can you, but the clarity could be useful to others (including tired me after a long day!).
Yes it wastes a bit of processing time and memory, but if what you are doing is going to significantly benefit from that small saving is the shell the right place to be doing it anyway?
- Ambroisie 6y agoYou can put the redirection before the command name, which keeps the same left to right flow.
- dspillett 6y agoThough the arrow still points the wrong way, if I'm being fussy. I was also about to suggest that was shell specific so not available everywhere, but a quick test says it is supported by /bin/sh at least so might be POSIX and therefore widely available.
- VBprogrammer 6y agoThis argument has been done to death. For the record yes, I agree with all of that and secretly I use it all the time. I only invoked the "useless use of cat" demon because in this case it makes an interesting difference. Less doesn't evaluate the escape sequences which make this attack work by default.