Close Terminal window from within shell script (Unix)?

Using exit 0 will cleanly terminate the script.

Whether Terminal window stays open is user-configurable. The default is to always stay open. To change this:

Terminal.app > Preferences > Profiles > Shell
    - "When the shell exists:"
        > Close if the shell exited cleanly
    - "Ask before closing:"
        (•) Never
        -- OR --
        (•) Only if there are....

When “Close if shell exited cleanly” is used, the script will close the window if the exit result is 0, which is the default if nothing went wrong.

Leave a Comment