command 1: cat file1 > file2
(success)
command 2: 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?
Asked
Active
Viewed 1,297 times
1

Prem
- 115
- 5
1 Answers
2
The redirection in
cat file1 >file2
is an output redirection, while <
specifies an input redirection.
The line
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 file2
with file1
as argument, and redirect the standard input from the file cat
".
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 file2
.

Kusalananda
- 333,661
>
sends output to a file,<
uses a file as input. – cylgalad Feb 23 '18 at 08:33