Bug 692517 - zsh code block/pipe problem
Summary: zsh code block/pipe problem
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: zsh
Version: 5.5
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: James Antill
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-03-31 13:18 UTC by D Newport
Modified: 2011-03-31 19:42 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-03-31 19:42:16 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description D Newport 2011-03-31 13:18:44 UTC
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 19:42:16 UTC
 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.