Skip to main content
Bounty Awarded with 100 reputation awarded by CommunityBot
added 111 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441
  1. The script runs to end of the script. The exit status of the script is that of the last command executed.
  2. The script runs the exit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -e/set -o errexit is in effect. The exit status is that of the failing command. (But see BashFAQ 105 for issues with set -e.)
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.(*)
  1. The script runs to end of the script. The exit status of the script is that of the last command executed.
  2. The script runs the exit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -e/set -o errexit is in effect. The exit status is that of the failing command.
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.(*)
  1. The script runs to end of the script. The exit status of the script is that of the last command executed.
  2. The script runs the exit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -e/set -o errexit is in effect. The exit status is that of the failing command. (But see BashFAQ 105 for issues with set -e.)
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.(*)
added 14 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441
  1. The script runs to end of the script. The exit status of the script is that of the last command executed.
  2. The script runs the exit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -e/set -o errexit is in effect. The exit status is that of the failing command.
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.(*)
  1. The script runs to end of the script. The exit status is that of the last command executed.
  2. The script runs the exit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -e/set -o errexit is in effect. The exit status is that of the failing command.
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.(*)
  1. The script runs to end of the script. The exit status of the script is that of the last command executed.
  2. The script runs the exit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -e/set -o errexit is in effect. The exit status is that of the failing command.
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.(*)
added 580 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441
  1. The script runs to end of the script. The exit status is that of the last command executed.
  2. The script runs the exit commandexit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -uset -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -eset -e/set -o errexit is in effect. The exit status is that of the failing command.
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signala signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the trapSIGINT commandsignal.(*)

This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.

In 4 to 6, the situation is usually considered some sort of a failure, so the exit status is non-zero. In 7, there is no exit status. Instead, when a process terminates due to a signal, the wait() system call indicates the signal in question. If the parent process is a shell, it usually represents this with an exit status of 128 + <signal number>, e.g. 143 for a child terminated with SIGTERM.

(* Unlike scripts, interactive shells will not exit due to syntax errors or set -u or SIGINT.)

  1. The script runs to end of the script. The exit status is that of the last command executed.
  2. The script runs the exit command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)
  5. The script runs a command that fails while set -e is in effect. The exit status is that of the failing command.
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap command.

This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.

In 4 to 6, the situation is usually considered some sort of a failure, so the exit status is non-zero. In 7, there is no exit status. Instead, when a process terminates due to a signal, the wait() system call indicates the signal in question. If the parent process is a shell, it usually represents this with an exit status of 128 + <signal number>, e.g. 143 for a child terminated with SIGTERM.

  1. The script runs to end of the script. The exit status is that of the last command executed.
  2. The script runs the exit builtin command without arguments. Again, the exit status is that of the last command executed.
  3. The script runs the exit command with an argument. The exit status is the value of the argument.
  4. The script references an unset variable while set -u/set -o nounset is in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use 127.)(*)
  5. The script runs a command that fails while set -e/set -o errexit is in effect. The exit status is that of the failing command.
  6. The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use 1.)(*)
  7. The script receives a signal that causes it to terminate. Not all signals cause termination, and signals can be either ignored or a handler can be set within the script with the trap builtin command. This also applies to e.q. hitting Ctrl-C, which sends the SIGINT signal.(*)

In 4 to 6, the situation is usually considered some sort of a failure, so the exit status is non-zero. In 7, there is no exit status. Instead, when a process terminates due to a signal, the wait() system call indicates the signal in question. If the parent process is a shell, it usually represents this with an exit status of 128 + <signal number>, e.g. 143 for a child terminated with SIGTERM.

(* Unlike scripts, interactive shells will not exit due to syntax errors or set -u or SIGINT.)

added 140 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441
Loading
added 179 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441
Loading
added 24 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441
Loading
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441
Loading