Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

$? and suspended jobs



~$ sleep 4; echo $?, $pipestatus
^Z
zsh: suspended  sleep 4
20, 0


Why not 128+20 = 148? I'd expect $pipestatus to contain the same
value as $?

~$ {sleep 5; echo $?}
^Zzsh: suspended  { sleep 5; echo $?; }
(20)1~$ fg
[1]  + continued  { sleep 5; echo $?; }
20

(that "(20)" is $? in my prompt). Here `echo $?` is run after sleep
finishing and returning a 0 exit status. Still $? is always
based on SIGTSTP.

~$ {(sleep 5; echo "$?"; exit 12); echo $?, $pipestatus}
^Zzsh: suspended  { ( sleep 5; echo "$?"; exit 12; ); echo $?, $pipestatus; }
(20)1~$ fg
[1]  + continued  { ( sleep 5; echo "$?"; exit 12; ); echo $?, $pipestatus; }
0
20, 0

$? is always 20 and $pipestatus always 0 regardless of the exit
status of the command that is resumed.

You might say there's value in that (one may want to consider a
command that was suspended as having failed), but the behaviour
is quite surprising.

Spawned from a question at:
http://unix.stackexchange.com/questions/151376/how-do-i-gracefully-suspend-and-resume-cmd1-cmd2-cmd3-chain

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author