Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
how do I close terminal window once sh file calls exit?

Solved 2 Answers 43 Views Others
0 2
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
Best answer
0

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).

answered by (151 points)
selected by
0
0

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.

 

answered by (151 points)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...