LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 12-22-2005, 06:29 PM   #1
ggeeoo
LQ Newbie
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 12

Rep: Reputation: 0
changing path from a bash script


I have added the following lines:

Code:
PATH=$PATH:/new/path
export PATH
into .bash_profile and works fine but I would prefer to have a script that I would call run whenever I need to temporarily add "/new/path" into $PATH. So I tried using the above two lines but the change made to $PATH is visible only by the script itself.
 
Old 12-22-2005, 07:02 PM   #2
Gsidious
Member
 
Registered: Nov 2005
Location: Oregon
Distribution: Ubuntu
Posts: 64

Rep: Reputation: 17
You need to "source" the script to have the change exist after the script has been run. So if your script was called "test.sh" and you type "./test.sh", the change won't exist after the script has been run, it was executed in a new shell which doesn't exist after the script completes. But if you "source" it like this: "source test.sh" the change will persist as it will be run in the current shell, not a sub-shell, so any command run after that from that shell will have the desired $PATH. You can also source a file like this: ". source.sh".
HTH.
-G.
 
Old 12-22-2005, 07:33 PM   #3
ggeeoo
LQ Newbie
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 12

Original Poster
Rep: Reputation: 0
Unfortunately this doesn't work for me as I get an "ELF: command not found" error. I just tried to type the following:
Code:
bash --init-file test.sh
and it works but then I have to type exit twice to logoff instead of once so it would be nice to have "source" work.

Last edited by ggeeoo; 12-23-2005 at 07:16 AM.
 
Old 12-23-2005, 11:17 AM   #4
Gsidious
Member
 
Registered: Nov 2005
Location: Oregon
Distribution: Ubuntu
Posts: 64

Rep: Reputation: 17
Code:
bash --init-file test.sh
Not sure why you are trying the "bash --init-file", just try this:
Code:
. test.sh
that's just a period followed by a space, then the name of the shell script, and it should work. HTH...
 
Old 12-23-2005, 04:10 PM   #5
ggeeoo
LQ Newbie
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Gsidious
... that's just a period followed by a space, then the name of the shell script, and it should work. HTH...
As I said in my previous post, this doesn't work as I get an "ELF: command not found" error.
 
Old 12-26-2005, 10:50 PM   #6
nitinatindore
Member
 
Registered: Dec 2004
Location: India
Distribution: Mandrake, Mandriva, PclinuxOS
Posts: 114

Rep: Reputation: 15
try out this

make an entry into your $HOME/.bash_profile

addToPath()
{
PATH=$PATH:/new/path;
export PATH;
}

that's it done! Now whenever you want to append path to your current path just write this on shell prompt.
$ addToPath
 
Old 01-04-2006, 06:24 PM   #7
Geminias
Member
 
Registered: Sep 2005
Posts: 201

Rep: Reputation: 30
how do you add an entry to ./bash_profile ??
 
Old 01-04-2006, 06:35 PM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by Geminias
how do you add an entry to ./bash_profile ??
Just as you would with any text file---with a text editor.

Depending on permissions, you may need to open the file as root to be able to change it. In Gnome, sudo gedit <filename> (or just su, then gedit)
 
  


Reply



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
Need help with finding path in bash script ylikone Linux - Software 1 08-02-2005 10:47 AM
changing the path liljhand Linux - Software 5 01-30-2005 04:37 AM
$PATH keeps changing? linux_dejan Linux - Software 1 04-11-2004 03:32 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
Changing PATH on the fly in BASH scripts pioniere Programming 1 06-17-2003 04:52 PM

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

All times are GMT -5. The time now is 09:28 PM.

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