I came across this problem now several times and I would like to find a way to automate/script this things that involves a change of identity or environment (I am not sure how to call that precisely).
An easy example would be a script where a part has to be executed with
make install for instance). To achieve this one could use
sudo. However there are other environment changes that do not have such an escape solution. Probably well known is the python virtualenv where one could easily imagine a script like
source virtEnv/bin/activate python myScript.py
or simply a script that invokes
screen. Now I am compiling gstreamer which I would like to automate in a script, because I will have to deploy this installation in several other computers later
for i in gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-python gnonlin gst-ffmpeg do gst-head cd ./$i git checkout tags/1.1.1 ./autogen.sh make -j7 exit done
gst-head is the
gst-uninstalled script that loads a local pkg_config (if I am right) and puts me in a separate environment. If I put that in a script the script will stop its execution there and continues once I do
exit from that environment.