Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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/com.apple.Terminal.plist

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

Your Answer

 
discard

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.