Re: $? in the right side of a pipe

2010-09-06 Thread Roman Rakus

 On 09/05/2010 11:36 AM, Pierre Gaston wrote:

using the following:

false; : | echo $?

bash and ksh93 print 0
pdksh, dash and zsh print 1

It's not especially useful, but I'm wondering if there is any reason
for this. (I would expect 1)

Thanks
Pierre


In bash, echo is run in the subshell. I'm not sure about the other shells.

RR



Re: $? in the right side of a pipe

2010-09-06 Thread Chet Ramey
On 9/5/10 5:36 AM, Pierre Gaston wrote:
> using the following:
> 
> false; : | echo $?
> 
> bash and ksh93 print 0
> pdksh, dash and zsh print 1

It looks like bash and ksh93 wait for each command in a pipeline to finish
and allow the intermediate commands to set $?, which, depending on timing,
can be seen by subsequent commands in the pipeline.  The other shells must
do something different.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/