- The script runs to end of the script. The exit status of the script is that of the last command executed.
- The script runs the
exitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -e/set -o errexitis in effect. The exit status is that of the failing command. (But see BashFAQ 105 for issues withset -e.) - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends theSIGINTsignal.(*)
- The script runs to end of the script. The exit status of the script is that of the last command executed.
- The script runs the
exitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -e/set -o errexitis in effect. The exit status is that of the failing command. - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends theSIGINTsignal.(*)
- The script runs to end of the script. The exit status of the script is that of the last command executed.
- The script runs the
exitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -e/set -o errexitis in effect. The exit status is that of the failing command. (But see BashFAQ 105 for issues withset -e.) - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends theSIGINTsignal.(*)
- The script runs to end of the script. The exit status of the script is that of the last command executed.
- The script runs the
exitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -e/set -o errexitis in effect. The exit status is that of the failing command. - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends theSIGINTsignal.(*)
- The script runs to end of the script. The exit status is that of the last command executed.
- The script runs the
exitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -e/set -o errexitis in effect. The exit status is that of the failing command. - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends theSIGINTsignal.(*)
- The script runs to end of the script. The exit status of the script is that of the last command executed.
- The script runs the
exitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -e/set -o errexitis in effect. The exit status is that of the failing command. - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends theSIGINTsignal.(*)
- The script runs to end of the script. The exit status is that of the last command executed.
- The script runs the
exitcommandexitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -uset -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -eset -e/set -o errexitis in effect. The exit status is that of the failing command. - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends thetrapSIGINTcommandsignal.(*)
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.)
- The script runs to end of the script. The exit status is that of the last command executed.
- The script runs the
exitcommand without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -uis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.) - The script runs a command that fails while
set -eis in effect. The exit status is that of the failing command. - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.) - 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
trapcommand.
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.
- The script runs to end of the script. The exit status is that of the last command executed.
- The script runs the
exitbuiltin command without arguments. Again, the exit status is that of the last command executed. - The script runs the
exitcommand with an argument. The exit status is the value of the argument. - The script references an unset variable while
set -u/set -o nounsetis in effect. The exit status depends on the shell, but is nonzero. (Bash seems to use127.)(*) - The script runs a command that fails while
set -e/set -o errexitis in effect. The exit status is that of the failing command. - The script runs into a syntax error. The exit status of the shell is nonzero. (Bash seems to use
1.)(*) - 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
trapbuiltin command. This also applies to e.q. hitting Ctrl-C, which sends theSIGINTsignal.(*)
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.)