Both of the following commands try to open a non-existing file
foo, but the error messages are a little different. What could be the reason?
$ cat foo cat: cannot open foo $ cat < foo -bash: foo: No such file or directory
This runs the
cat command with argument
foo. The error printed onscreen depends entirely on what was decided by the programmer of the command.
cat < foo
This feeds the contents of the file
foo to the
cat command by using the Bash stdin redirection. If the file doesn't exist, it is Bash that complains about it.
$ cat foo the shell (here bash) executes the
cat command and passes the parameter
foo. The cat program chooses to interpret that parameter as a file name - and tries to open the file.
The error you see is from the cat program which (naturally) cannot open the file.
$ cat < foo is a redirection which is handled by the shell.
< is a shell operator which instructs the shell to open a file and redirect it to stdin. The file does not exist so you get a "No such file". This time the error comes from the shell (bash) and looks a little different.
This is why you see 2 different errors. The cause is the same - but it is from 2 different programs (cat and bash).