views:

65

answers:

2

I'd like to do something like:

do lots of stuff to prepare a good environement
become_interactive
#wait for Ctrl-D
automatically clean up

Is it possible with bash? If not, do you see another way of doing the same thing?

+2  A: 

You can invoke another shell in the middle of the script, but changes to e.g. environment variables would not be reflected outside of it.

Ignacio Vazquez-Abrams
+5  A: 

Structure it like this:

test.sh

#!/bin/sh
exec bash --rcfile environ.sh

environ.sh

cleanup() {
    echo "Cleaning up"
}
trap cleanup EXIT
echo "Initializing"
PS1='>> '

In action:

~$ ./test.sh 
Initializing
>> exit
Cleaning up
jleedev