It makes no sense. Starting your pipe with cat is alright. I make a point of always starting all my pipes with cat, even in the cases where it is a bit unnatural.
It makes no sense. Starting your pipe with cat is alright. I make a point of always starting all my pipes with cat, even in the cases where it is a bit unnatural.
For those who may not know, you can put the I/O redirection anywhere in the command, not just at the end.
So you can write
< input_file.txt grep some_pattern | grep another
Which has the same effect as grep some_pattern < input_file.txt | grep another
but puts the input redirection at the beginning so you can easily follow the data flow from left to right.I use "redirection first" in other cases such as
1>&2 echo "Error: missing file"
To make it clear up-front that I'm writing to stderr.
cat file |\
program1 |\
program2 |\
...
If you use a redirection, since the command does not start with a pipe the symmetry is broken.Redirections at the start of the line are fun. I have an alias
alias null='>/dev/null 2>/dev/null'
this allows to run GUI programs without cluttering the terminal with useless GTK/QT warnings: null evince file.pdfEdit:
cat file |
program1 |
program2 |
... echo foo | # echoing foo
tr 'a-z' 'A-Z'
FOOI typically start with (say) `head file | grep '2020'`. Once it does what I want I move to the next step, and so on until it's done. At that point, and having chained 5-6 commands, replacing `head` with `cat` is faster and less likely to break due to me putting the '<' in the wrong place. The simplicity and extra peace of mind is well worth an extra process IMHO.
It's a good thing to be aware of the differences when needed, but often the execution speed is not the reason for writing a bash script.
cat file.txt | somemonstrousoneliner
immediately tells me it's reading file.txt and doing something with the contents.
Burying the filename deeper in the string makes it harder to figure that out.