Results 1 to 5 of 5
Im in a networking class and we are learning how to program some basic linux commands. But everytime we create a script we have to change the path to start ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-28-2004 #1Just Joined!
- Join Date
- Apr 2004
- Posts
- 2
Creating a Script to Manualy change Path
Im in a networking class and we are learning how to program some basic linux commands. But everytime we create a script we have to change the path to start it so i was trying to create a script to change it for all the students in the class but i ran into some problems heres my code.
echo "Enter in your directory starting after $HOME/"
read answer
PATH=$PATH:$HOME/$answer
echo $PATH
when i do this script it shows it works when i echo the $PATH but when i echo it Manualy at my promt after the scripts done it doesn't show the changes. I should also note that im telneting into a linux server to do this but i don't know if that can have an impact.
- 04-28-2004 #2Linux Newbie
- Join Date
- Aug 2001
- Location
- USA, Texas
- Posts
- 217
When you run the script it creates its own environment (simplified for clarity ??). It gets a copy of all of the current env. variables. When you modify a variable in a script it modifies only its copy and does not affect the copy being used by your shell.
Code:FILE: path.scr echo $PATH export PATH=$PATH:$HOME/subfolder echo $PATH
You can source a file to update your path... like what happens to the .bash_profile, your script file may work like that. Not sure but couldn't hurt to give it a try.Code:bash$ echo $PATH /usr/bin:/usr/local/bin:/home/sykkn/bin bash$ sh path.scr /usr/bin:/usr/local/bin:/home/sykkn/bin /usr/bin:/usr/local/bin:/home/sykkn/bin:/home/sykkn/subfolder bash$ echo $PATH /usr/bin:/usr/local/bin:/home/sykkn/bin
sourcing: bash$ . path.scr
//EDIT: that really is just a period and then the name of the script[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don\'t make me use it! */
- 04-28-2004 #3Just Joined!
- Join Date
- Apr 2004
- Posts
- 2
Thanks
Your tip was very useful and i found another way also with both of the ideas it will work nicely.
- 04-30-2004 #4Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Another option is to add code to your ~/.bash_profile - it is sourced every time you log in.
- 05-26-2004 #5Just Joined!
- Join Date
- May 2004
- Posts
- 1
Re: Thanks
Hi!
Originally Posted by SlyGuy
was going through the posts - I am facing the same problem and have not been able to solve it as yet. Could u please let me know in detail how to go about changing PATH from a script.
A quick response will be highly appreciated.
Thanks


Reply With Quote
