zsh-workers
 help / color / mirror / code / Atom feed
* $? and suspended jobs
@ 2014-08-21 19:37 Stephane Chazelas
  2014-08-21 21:31 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Stephane Chazelas @ 2014-08-21 19:37 UTC (permalink / raw)
  To: zsh-workers

~$ 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-22  1:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-21 19:37 $? and suspended jobs Stephane Chazelas
2014-08-21 21:31 ` Bart Schaefer
2014-08-22  1:45   ` [PATCH] " Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).