Bug 692517 - zsh code block/pipe problem
zsh code block/pipe problem
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: zsh (Show other bugs)
5.5
x86_64 Linux
unspecified Severity medium
: rc
: ---
Assigned To: James Antill
BaseOS QE - Apps
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-31 09:18 EDT by D Newport
Modified: 2011-03-31 15:42 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-03-31 15:42:16 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description D Newport 2011-03-31 09:18:44 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:
Comment 1 James Antill 2011-03-31 15:42:16 EDT
 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

Note You need to log in before you can comment on or make changes to this bug.