Red Hat Bugzilla – Bug 692517
zsh code block/pipe problem
Last modified: 2011-03-31 15:42:16 EDT
Description of problem: The following two examples show the problem: 1) typeset -i RC=0 { ls xxx 2>/dev/null; RC=$? } echo $RC 2 2) typeset -i RC=0 { ls xxx 2>/dev/null; RC=$? } | tee /tmp/yyy echo $RC 0 In 1) above the value in the RC env var is correct. When a |tee is added then it appears that the code block is executed as a subshell and hence RC is not set. Version-Release number of selected component (if applicable): zsh-4.2.6-3.el5 zsh-debuginfo-4.2.6-2.hotfix How reproducible: See examples above. Steps to Reproduce: 1. 2. 3. Actual results: Expected results: Additional info:
I believe this is intentional, in that only the _last_ command in a pipe is executed within the current shell and all the others are in subshells (with a couple of optimizations, for cases zsh knows you can't tell the difference). % print $ZSH_SUBSHELL 0 % print $ZSH_SUBSHELL | cat 0 % {print $ZSH_SUBSHELL} 0 % {print $ZSH_SUBSHELL} | cat 1 % echo | cat | {print $ZSH_SUBSHELL} 0 % print_sub () { print $ZSH_SUBSHELL } % print_sub 0 % print_sub | cat 1 % echo | cat | print_sub 0