Subject: Re: sh problem
To: Patrick Welche <>
From: Andrew Brown <>
List: current-users
Date: 01/25/2000 00:38:17
Content-Type: text/plain; charset=us-ascii

>> > It isn't clear to me what ! should do with the exit status of a
>> > subshell -
>> (How the exit status of the subshell relates to the exit status of
>> anything it runs is another question.  I imagine it's well-defined....)
>Exactly ;)

that's easy!  it's just like a shell script.

in a shell script, unless you exit with a specific return code, the
shell exits with the return code of the last process executed (weirdly
like perl in a macabre way).


   ( cmd1 ; cmd2 )
   cmd1 ; cmd2
   ( cmd1 | cmd2 )
   cmd1 | cmd2

all have the same exit code: that of cmd2.  therefore, the shell

   ! cmd1 [ | cmd2 ... ]

(a) should have the exit code of the last process in the pipeline (one
process is a one stage pipeline), and (b) should be so, regardless of
the presence of parentheses.

try the attached shell script.  for me it only prints 2s.

|-----< "CODE WARRIOR" >-----|             * "ah!  i see you have the internet (Andrew Brown)                that goes *ping*!"       * "information is power -- share the wealth."

Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=l


cat << 'EOF' > exitwhat
( sh -c 'exit 1' ; sh -c 'exit 2' );	echo $?
sh -c 'exit 1' ; sh -c 'exit 2';	echo $?
( sh -c 'exit 1' | sh -c 'exit 2' );	echo $?
sh -c 'exit 1' | sh -c 'exit 2';	echo $?

echo "trying sh...";			sh exitwhat
echo "trying bash...";			bash exitwhat
echo "trying ksh...";			ksh exitwhat
echo "trying zsh...";			zsh exitwhat
echo "trying csh...";			sed 's/?/status/' exitwhat | csh -f
echo "trying tcsh...";			tcsh -f exitwhat

rm exitwhat