When I use my shell’s redirection operator to provide a (non-existent)
filename to the grep
command, the error message about that file not
existing is displayed by my shell. But when I provide that same filename
as an argument to the grep
command, the corresponding error message is
displayed by the grep
command itself. Why is that?
Here’s a demonstration of what I’m talking about. When I run the command:
$ grep 'root' /etc/passw
I get the following error message:
grep: /etc/passw: No such file or directory
But when I run the command this way with shell redirection:
$ grep 'root' < /etc/passw
I instead get the following error message:
bash: /etc/passw: No such file or directory
What is the difference between these two methods of specifying the input filename, and is there any significance in having them behave this way?
grep
itself tries to read from the file. The way that the two differ varies from utility to utility.wc
) there is a significant difference, I'm sure there are more examples as well I just can't think of them right now.