Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I have a shell script that changes directory and then runs. I want the directory change to be bubbled to the command prompt once the script terminates.

So, I run it with:

. script

However, now when the script terminates, the whole window terminates. Is there a way to fix this?

My shell is bash.

share|improve this question
up vote 0 down vote accepted

There are two ways to remedy this in Mac

A> Go to your Preferences for Terminal, Select [General], and uncheck the box that says "Close window if shell exits cleanly".

B> Point your favourite text editor to ~/Library/Preferences/

Find the rows:

 < key>ShellExitAction< /key>
< integer>1< /integer>

change the 1 to a 2 and restart the terminal app..

B is basically the same as A, but done manually.

share|improve this answer
Also, you'll want to save the change in your standard Terminal profile, so it persists across new instances. – Greg Gauthier Oct 29 '10 at 18:59

Does script contain an exit statement? Remember that dot (sourcing) runs your code in the current shell. So if it has an exit, your current shell exits. You may want to check script and change any exit to return.

You may be able to detect being sourced (where you'd want to do return) and being run (where you may want exit)

[[ $BASH_SOURCE != $0 ]] && echo 'running sourced ...'
share|improve this answer
For shells that don't have $BASH_SOURCE, you can use $_ but you have to save it as the first thing in the script since the execution of each command overwrites it. – Dennis Williamson Oct 29 '10 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .