When I log in, my path is set to a list of directories. I need to write a script that will change the path and when it exits, retains the new path. Is this even possible? What would be a better approach?
You probably know this, but just making sure: the usual place to set your PATH is in a shell startup file such as [tt]~/.profile[/tt] or [tt]~/.cshrc[/tt].
It is impossible for a process to modify the environment of its parent process. That's why you have to "source" the script for the change to take place; a script that is sourced is executed directly by the calling shell, not by a subprocess.
Oh, and if the dot command shown above doesn't work, the [tt]source[/tt] command might. Depends on your shell family.
If you want to change the PATH variable every time you login, you can save yourself typing . /path/to/script at each login by editing the .profile (or for bash use .bashrc) in your home directory (as hinted at by chipperMDW).
In the .profile at the bottom, add the lines:
PATH=$PATH:/export/home/me
export PATH
thus appending your directory to the PATH variable.
Or use the following to re-define your PATH variable (in .profile or .bashrc):
PATH=/export/home/me
export PATH
Thanks for that, Mike042. I should have explained myself better earlier on. I'm fully aware of ~/.profile, ~/.bashrc, and ~/.cshrc. This carrying over of environment variables is supposed to occur after the login.
At first, I thought my dba wanted to redefine environment variables from a script and have that carry over once the script was finished. Apparently I misunderstood, because now he's talling me he wants to carry environment variables from script to script.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.