Cat gives different error when opening non-existing file

catcommand lineio-redirection

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

Best Answer

cat foo

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.

Related Question