Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I tell terminal to call the "exit" command automatically when I exit the terminal?

I am running Ubuntu Unity and using the default terminal program. I want to call "exit" before exiting terminal because, if I do not, then a certain process does not quit.

share|improve this question
Which certain process? How do you exit, by clicking the x or with Ctrl+D? – Baarn Sep 8 '12 at 21:30
up vote 0 down vote accepted

I assume you mean you want the shell running in the terminal to call a function before exit. In that case use trap, try this:

trap 'echo Hey' INT

Now send an interrupt signal to yourself:

kill -INT $$

Instead of echo Hey you can call an arbitrary function.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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