2 ms·
No, it makes much more sense to start with the command that is to process the file. Most commands take a command line argument to specify which file to process.
by xorcist 12y ago
No, it makes much more sense to start with the command that is to process the file. Most commands take a command line argument to specify which file to process. This mirrors the redirection syntax perfectly:
You say:
grep haystack needle.txt
or:
grep haystack < needle.txt
whereas this is more convoluted:
cat needle.txt | grep haystack
As a bonus the syntax looks the same for output redirection:
sort < infile.txt > outfile.txt
whereas this is not as readable:
cat infile.txt | sort > outfile.txt
What "makes sense" to you doesn't always to other people. In this case it's trivial, but it's a nightmare to debug larger scripts when there are lots of unnecessary redirections and if statements.
Shell scripts may be one-offs, but they tend to linger. It's not unwise to spend a few extra moments to make them readable and follow best practice. It is code after all.
(Also; a bit silly with the personal attacks.)