I write shell scripts to do various things in OSX and Linux, but I always have the same problem. The script runs but any changes it makes to the environment (except the disks, of course) do not "stick." When the script terminates the changes revert.
How can I make my changes stick?
Edit: A lot of the answers have been great, but they haven't helped the situation I'm facing tonight. I'm trying to run this to get my TAP interface working
sudo bash # we go superuser
exec 4<>/dev/tap0 # opens device, creates interface tap0
ifconfig tap0 10.10.10.1 10.10.10.255
ifconfig tap0 up
which works wonderfully if I paste it in, but not if I source it or sh it. BTW, I cannot close the terminal window afterwards as then I lose the tap0 interface.
Last Edit: Thanks everybody, the answer was to use source as you all suggested but to remove the sudo command from the script itself.