Close Terminal window from within shell script (Unix)?

ericsoco picture ericsoco · Jan 10, 2012 · Viewed 81.9k times · Source

Is there a way to close a Terminal window from within a shell script? I have a .command file that should just get out of the way once it's done.

Answer

Simon Urbanek picture Simon Urbanek · Jan 11, 2012

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.