25

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

44

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

  • Thank you very much. I had missed that option in the settings pane! – Auron Jul 31 '09 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 '16 at 18:51
  • 2
    @jmm for El Capitan: Preferences, Profiles, Shell, Set the "When the shell exits" dropdown as you wish. – Chaim Geretz Sep 22 '16 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}'`
  • 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. – Chris Stratton Jan 4 '17 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.