by teddyh · 7y ago · 0 comments
Rememeber, nearly all cases where you have:
cat file | some_command and its args ...
you can rewrite it as: <file some_command and its args ...
and in some cases, such as this one, you can move the filename to the arglist as in: some_command and its args ... file
— Randal L. Schwartz (http://porkmail.org/era/unix/award.html#cat)I actually prefer useless cat because when you're prototyping a pipeline it's very awkward to use non-useless cat. You'll probably start off with something like this to observe the content of the file:
cat something.txt
Using this doesn't work in bash: <something.txt
Then, continuing with useless cat to build on it you do cat something.txt | grep stuff
Which you can type easily from using 'up' in your terminal. But if you use non-useless cat you have to re-type the entire thing or move the cursor around: grep stuff < something.txt
With useless cat, you can keep adding things and check the result: cat something.txt | grep stuff | sed 's/"//g'
Or if you need to insert another filter before the last stage like this, you can just press "up" and insert it: cat something.txt | grep -v negmatch | grep stuff
I don't think there is any easily-typed equivalent workflow with non-useless cat.<file head -n50 | whatever
Can be the starting command. When you no longer need the head there, just get rid of “head |”.
Although I agree that the pointing out of “useless cat” is usually not particularly useful or constructive.
cat foo | bar
is useless use of cat, since it’s equivalent to < foo bar
which is both shorter and starts one less process. Why do you think that “cat” makes it “easier to author pipelines”?2). I often start with `bar < foo`, so if I need to add more arguments to `bar`, I need to always skip over the input.
3). If I just want to delete all processing and look at the input, I can’t just backspace away the processing because `< foo` is invalid.