Skip to main content
adding some crucial tags, otherwise people don't find this; edited tags
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
adding some crucial tags, otherwise people don't find this
Link
Source Link
Eugene Yarmash
  • 15.7k
  • 14
  • 54
  • 60

Why does bash set $? (exit status) to non-zero on Ctrl-C or Ctrl-Z?

From the bash manual, on the $? variable:

$? Expands to the exit status of the most recently executed foreground pipeline.

I wonder why bash updates the $? variable on pressing Ctrl-C or Ctrl-Z:

$ echo $?
0
$ ^C
$ echo $?
130
$ sleep 10
^Z
[1]+  Stopped                 sleep 10
$ echo $?
148