In very lot of answers, mainly about text-processing commands, I saw commands such as sed, awk, grep, among other, being used with STDIN and the simple open of a file
e.g.
$ sed -e 's|foo|bar|g' file # open file
$ sed -e 's|foo|bar|g' <file # open STDIN
or
$ grep 'PATTERN' file # open file
$ grep 'PATTERN' <file # open STDIN
In a personal, I use the open file method always, but I want to know when and when not to use them, also what's the difference.
file. The shell merely opensfilethen manipulates file descriptors (e.g. usingdup2) so thatfileis available on descriptor 0 (standard in). The shell will thenexecgrep, replacing itself and allowinggrepto read standard input as it pleases. – Barefoot IO Mar 04 '16 at 00:08