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?
info libc
(glibc-doc
package in Debian and derivatives) to be invaluable resource for understanding file and process model of a typical nix system. – alex Jul 22 '11 at 13:15