cat file1 > file2 (success)
file2 < cat file1 (cat : No such file or directory)
I just wanted to know the general syntax of output and input redirections.
If redirection can happen to file or stream, why command 2 fails?
The redirection in
cat file1 >file2
is an output redirection, while
< specifies an input redirection.
file2 < cat file1
is the same as
file2 file1 <cat
(it does not matter much where the redirection actually occurs as it's handled by the shell in its own parsing step and then removed from the actual command) which means "run
file1 as argument, and redirect the standard input from the file
The error comes from the shell trying to open
cat as a file in the current directory. The error occurs before the shell tries to run the command