LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2012, 08:15 AM   #1
pppaaarrrkkk
Member
 
Registered: Jun 2005
Location: Aylesbury UK
Distribution: Red Hat enterprise linux 6
Posts: 101

Rep: Reputation: 15
Write shell script to change PATH


The following work when run at CL, but not as a script, although the echo command correctly echoes the 'new' path. Help appreciated.


PATH=$PATH:/home/qq/dir1/
export PATH

echo $PATH
 
Old 07-17-2012, 08:25 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,475

Rep: Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770Reputation: 7770
use source <srcipt>
 
Old 07-17-2012, 09:52 AM   #3
pppaaarrrkkk
Member
 
Registered: Jun 2005
Location: Aylesbury UK
Distribution: Red Hat enterprise linux 6
Posts: 101

Original Poster
Rep: Reputation: 15
Thanks.
 
Old 07-17-2012, 12:06 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
PATH, being an environment setting, can only be set from inside the shell that uses it. This means that you cannot use any external scripts to change it. The command in the script only changes the script's environment, which is lost when it closes.

I wrote up a detailed explanation of how the environment works the last time someone asked about this. You might have found it if you had done a search before posting.

http://www.linuxquestions.org/questi...2/#post4725166

The only ways you can change the PATH, other than manually, are through A) sourcing, which imports the code into the current shell's environment and executes the commands there, or B) through the use of a shell function, which is like a script, but sits inside the current environment and therefore can affect it directly.

http://mywiki.wooledge.org/BashGuide...ands#Functions
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 07:24 AM
Shell script help: How to pass a directory path to the script? dv502 Programming 13 09-10-2008 04:07 AM
script to change unix path to windows path in all files csross Programming 8 04-29-2006 02:05 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 04:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration