Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
1.3k views
in Others by
retagged by
I am executing sh script and at the end I am doing exit. It complets process and logs out sucessfully but it does not close terminal window it opened on Mac. How do I close terminal window once sh file calls exit?

2 Answers

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

Using exit 0 will cleanly terminate the script, but whether Terminal window stays open is user-configurable in Terminal's preferences. The default is to alway stay open, but I prefer the setting "Close if shell exited cleanly". It can be changed in Settings -> Shell -> When the shell exists. With that setting the script will close the window automatically if the exit result is 0 (which is the default if nothing went wrong).

0 like 0 dislike
by The go-to Tester (181 points)

You can use apple script to quit the terminal app. Add the following to your script -

osascript -e 'tell application "Terminal" to quit'

This will give you a popup confirming to close the app. You can disable this in Terminal preferences.

Alternatively, you can also use killall command to quit the app. The following would work just as well.

killall Terminal

Note:

Just as a side note, you can freely add the above commands to your script and it would work as you want. However, there are few caveats. First being you will limit the ability of your script to work on different boxes. Secondly, it would be safer to use nohup so that any commands that are currently running won't quit due to quitting of the Terminal app.

 


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...