Let’s say you don’t want to have certain variables set every time (through .bashrc). Setting them up by running a script doesn’t exactly do what you want: it sets up your variables in the environment in the script, and then exits that environment on exiting the script.
Bash features a built-in command “source scriptname.sh” to do the thing: it executes the commands in the script in the current environment. Here’s an example (this is what I wanted to do today, setting extra library and header search paths for gcc):
which, as a bonus, brings me straight to the right working directory to get on the job…
I found this solution starting here from a google search. The gcc variables are described in the book “An introduction to GCC” by Brian Gough, which is in fact also available online.