Skip to main content
Correct explanation of `exit` with no argument.
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

There aren't really different "modes" of exiting.

Using exit 0 is simply explicitly settingwith no argument will use the return code to the default of 0the previous command as the return code. Which If this is to say thatthe final command in a script, it is effectively a NOOP unless the script is being exitsource and d.

exit 0 are functionally identical; similar tois explicitly setting the 'difference' between ls andreturn code to ls .0, the standard exit code for a non-error state.

Using a number other than 0 is simply doing the same thing: setting the return code to the specified value (or, absent specification, the default of zero).

When a script ends without an exit instruction, the exit code of the final command executed by the command is used.

If you trap '[...]' EXIT, and include an exit statement in the trap, it will supercede this as the trap will be executed (including any included exit commands) before the script actually terminates.

There aren't really different "modes" of exiting.

exit 0 is simply explicitly setting the return code to the default of 0. Which is to say that exit and exit 0 are functionally identical; similar to the 'difference' between ls and ls ..

Using a number other than 0 is simply doing the same thing: setting the return code to the specified value (or, absent specification, the default of zero).

When a script ends without an exit instruction, the exit code of the final command executed by the command is used.

If you trap '[...]' EXIT, and include an exit statement in the trap, it will supercede this as the trap will be executed (including any included exit commands) before the script actually terminates.

There aren't really different "modes" of exiting.

Using exit with no argument will use the return code of the previous command as the return code. If this is the final command in a script, it is effectively a NOOP unless the script is being sourced.

exit 0 is explicitly setting the return code to 0, the standard exit code for a non-error state.

Using a number other than 0 is simply doing the same thing: setting the return code to the specified value.

When a script ends without an exit instruction, the exit code of the final command executed by the command is used.

If you trap '[...]' EXIT, and include an exit statement in the trap, it will supercede this as the trap will be executed (including any included exit commands) before the script actually terminates.

Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

There aren't really different "modes" of exiting.

exit 0 is simply explicitly setting the return code to the default of 0. Which is to say that exit and exit 0 are functionally identical; similar to the 'difference' between ls and ls ..

Using a number other than 0 is simply doing the same thing: setting the return code to the specified value (or, absent specification, the default of zero).

When a script ends without an exit instruction, the exit code of the final command executed by the command is used.

If you trap '[...]' EXIT, and include an exit statement in the trap, it will supercede this as the trap will be executed (including any included exit commands) before the script actually terminates.