Piping and redirection are processed from left to right.
So first the input of cat
is redirected to the pipe. Then it is redirected to /etc/issue
. Then the program is run, using the last redirection, which is the file.
When you do cat <file1 <file2
, stdin is first redirected to file1
, then it is redirected to file2
. Then the program is run, and it gets its input from the last redirection.
It's like variable assignments. If you do:
stdin=passwd
stdin=issue
The value of stdin
at the end is the last one assigned.
This is explained in the bash
documentation, in the first paragraph of the section on Redirection:
Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell. Redirection may also be used to open and close files for the current shell execution environment. The following redirection operators may precede or appear anywhere within a simple command or may follow a command. Redirections are processed in the order they appear, from left to right.
(emphasis mine). I assume it's also in the POSIX shell specification, I haven't bothered to look it up. This is how Unix shells have always behaved.