IO Redirection – Difference Between ‘cat’ and ‘cat <'

catio-redirection

I was working through a tutorial and saw use of both cat myfile.txt and cat < myfile.txt. Is there a difference between these two sequences of commands? It seems both print the contents of a file to the shell.

Best Answer

In the first case, cat opens the file, and in the second case, the shell opens the file, passing it as cat's standard input.

Technically, they could have different effects. For instance, it would be possible to have a shell implementation that was more (or less) privileged than the cat program. For that scenario, one might fail to open the file, while the other could.

That is not the usual scenario, but mentioned to point out that the shell and cat are not the same program.

Related Question