26

Whenever I type 'exit' or I logout, the terminal window stays open and I have to close it manually. Can I change this behavior?

2 Answers 2

45

Go to Terminal -> Preferences, then on the right hand side select "Shell", then select "Close if the shell exited cleanly" from the dropdown labeled "When the shell exits".

This will close the shell if it exited without a problem (such as when you typed "exit"), but if the process returns an error it will stick around so that you can see what it was.

visual depiction of the menu

3
  • Thank you very much. I had missed that option in the settings pane!
    – Auron
    Jul 31, 2009 at 21:15
  • 1
    Any ideas on how to make this work in El Capitán? This has changed, and I can't find that "When the shell exits" combo anymore
    – jmm
    Sep 20, 2016 at 18:51
  • 2
    @jmm for El Capitan: Preferences, Profiles, Shell, Set the "When the shell exits" dropdown as you wish. Sep 22, 2016 at 17:24
2

Additionally, you can execute the following command (or add it to the end of your .sh shell script) in order to kill the Terminal application:

kill `ps -A | grep -w Terminal.app | grep -v grep | awk '{print $1}'`
1
  • This will kill all Terminal windows, not just the one running the application. So it is only useful to those who don't use Terminal windows for any other purpose but the proposed automation. Jan 4, 2017 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.