What is the order of commands executed which have both pipeline and output redirection in it?
Say we do the following:
Charles@myzone:/tmp$ mkdir /tmp/testdir Charles@myzone:/tmp$ cd /tmp/testdir Charles@myzone:/tmp/testdir$ touch file1 file2 Charles@myzone:/tmp/testdir$ ls | wc -l 2 Charles@myzone:/tmp/testdir$ ls | wc -l > ls_result Charles@myzone:/tmp/testdir$ cat ls_result 3
I know that if you do
ls > result then
result will contain the name of itself because the shell will do something like
1) create/open file named
2) set the fd of
result to be stdout
I was expecting
ls_result to have value 2, but it's 3.
How is the command
ls | wc -w > ls_result above executed ?
Is it equivalent to
(ls | wc -w ) > ls_result?
Some links with concerning information ? (I've looked up the bash manual)