For some commands, it is possible to specify certain input as either stdin or a command line argument.
Specifically, suppose command
can take stdin input and a filename as command line argument, and command < myfile
, cat myfile | command
and command myfile
can produce the same result.
For example,
When the command is sed
:
sed s/day/night/ <myfile >new
sed s/day/night/ myfile >new
cat myfile | sed s/day/night/ >new
When the command is cat
:
cat < myfile
cat myfile
- I was wondering if there are some general rules about their performances, i.e. which one of them is usually the most efficient, and which the least?
- Is redirection always better than pipe?