I was trying to run the command given below
cat numbers.txt | sort < words.txt
The above command has a pipe from cat command feeding to input stream of sort command. But at the same time, input stream of the sort command is also redirected to the words.txt file. On running the command i found that the data from words.txt is sorted by the sort command and displayed back in terminal.
I don't understand how the shell processes the piping and redirection in such a case. Is it possible for one command to accept input stream from two different sources. My thoughts on how it worked internally was that, since redirection and piping are handled from left to right along the command, first the output stream of the cat command will be fed as the input stream for sort command. But since sort command is provided with another input stream redirection after this pipe, the input stream of sort command will be then be connected to words.txt. So when the command executes, data from words.txt would only reach sort command.
Also why isn't the following command not running.I have changed the redirection by overwriting to redirection by appending.
cat numbers.txt | sort << words.txt
There is a question partly similar to this, but i couldn't exactly understand how the pipe and redirection was handled by the shell.