Results 1 to 5 of 5
The following script is expected to update the $PATH environment variable with the result of 'pwd' command, however it does not work on CentOS 5.2:
#/bin/bash
export working_path=`pwd`
#echo $working_path
...
- 10-09-2008 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 8
scripting help
The following script is expected to update the $PATH environment variable with the result of 'pwd' command, however it does not work on CentOS 5.2:
#/bin/bash
export working_path=`pwd`
#echo $working_path
export PATH=$PATH:$working_path
- 10-09-2008 #2
Are you sure? Try echo'ing $PATH at the end of that script and see what it says. Note that (to the best of my knowledge, I could be wrong) a script like this will run in its own sub-shell of your original shell. Therefore, when this script exists, there will appear to be no change to the environment variables of your original, interactive shell.
If you want to change your "normal" shell, try just executing
at the command prompt. That should achieve the correct effect. (You can also do it this way in your script, eliminating the need for the working_path variable.)Code:export PATH=$PATH:`pwd`
Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com
- 10-09-2008 #3Linux User
- Join Date
- Jun 2007
- Posts
- 318
As danielsmw mentioned when you normally execute a script it runs in a child process so the change isn't in your shell environment. To execute the script in the current shell environment use either method:
orCode:source /path/to/script
Code:. /path/to/script
- 10-09-2008 #4Just Joined!
- Join Date
- Nov 2007
- Posts
- 8
- 10-13-2008 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
If you want to do this, use a function. You can define something like this on your .bashrc/.bash_profile,
Functions will run on the same shell you invoke them. So, you can just do:Code:# Function to add a path # Usage: add_path <path> add_path () { if [ "$PATH" == "${PATH/$1/}" ] then PATH="$1:$PATH" export PATH fi }
Code:add_path "/home/foo/my custom path"


Reply With Quote
