Here is a much concise example if someone cares :

cd / && cd /tmp/ | pwd  ; pwd
/
/

Or :

cd / && cd /tmp/ | cd /var/  ; pwd
/

Or :

i=0;  i=1  | echo $i ; echo $i
0
0
idx=0; { ((++idx)); echo $idx >&2; } | echo $idx ; echo $idx
0
1
0

Yes this page says it all

http://linux.die.net/man/1/bash# Each command in a pipeline is executed as a separate process (i.e., in a subshell).

http://stackoverflow.com/questions/5760640/left-side-of-pipe-is-the-subshell/22054804#22054804

STATUS

f_()
{
    t=0
    { t=1; echo "inside subshell=$t" ; return $t ;} | cat

    echo PIPESTATUS=${PIPESTATUS[0]} # 0
    echo "outside subshell = $t" # 0


}

f_

@TaG: ArpalHands PipeFail

pipe.txt · Last modified: 2020/09/08 20:47 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki