Skip to main content
1 of 2
Kusalananda
  • 355.7k
  • 42
  • 735
  • 1.1k

An exit statement on the last line of a script is not necessary unless you want the script to terminate with some specific exit status, in which case you may want to use e.g. exit 0 to signal "success" or exit 1 to signal "failure", to the caller.

Without an argument, exit will terminate the script with whatever value $? is, i.e., with the exit status of whatever was the last command to execute (echo in your example). This also happens by default when the script runs to its end. An explicit exit or exit "$?" is therefore never needed.

Kusalananda
  • 355.7k
  • 42
  • 735
  • 1.1k