Reputation: 56262
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?
Upvotes: 5
Views: 383
Reputation: 177584
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
Upvotes: 8
Reputation: 798676
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.
Upvotes: 2