LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 04-19-2005, 10:37 PM   #1
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Rep: Reputation: 15
PATH statement from file


I have no more PATH statement, but before I accidentally nuked it, I saved it to a file called path. How could I redirect the contents of this file to my PATH statement? Is this even possible? I know I could do cat path (my filename) and just copy and paste it to PATH= but I do not want to do it that way. TIA!
 
Old 04-20-2005, 04:46 AM   #2
fuzzyash
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: Fedora Core 4
Posts: 184

Rep: Reputation: 30
For adding to every users path, find the line in /etc/profile that says something like

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

& on the line just above it type

PATH=$PATH:/THEN/YOUR:/CUSTOM/PATHS

each new path must be separated by a :

For individual users paths, type

PATH=$PATH:/THEN/YOUR:/CUSTOM/PATHS

into $HOME/.bash_profile & on the next line put:

export PATH
 
Old 04-20-2005, 03:12 PM   #3
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Original Poster
Rep: Reputation: 15
yea I know that. But what I want to do is redirect a file which has content like this...


/bin:/sbin:/usr/local/bin

to my actual path statement;from the file.
 
Old 04-20-2005, 09:23 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
You can do this (assuming you use the bash shell):
Code:
export PATH=$(cat path_file)
echo $PATH
EDIT:
Keep in mind, the contents of that file needs to be exactly the same as the PATH was previously. For instance, if it was created like so:
Code:
echo $PATH > path_file
If you did any sort of processing on it (like separating each directory onto its own line), then you'll have to reassemble it before the command I gave would work. It might be as simple as piping the cat through a tr command, or it could be very complex. It just depends on how/if you modified the data in that file to be something other than just a plain vanilla PATH format.

Last edited by Dark_Helmet; 04-20-2005 at 09:26 PM.
 
Old 04-20-2005, 10:50 PM   #5
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Original Poster
Rep: Reputation: 15
ah ha! I was missing the () around cat path_file

THX! It worked (but I had to take out the export).
 
Old 04-20-2005, 11:00 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
The export shouldn't cause you any problems. I'm not sure by your response whether it did, or if you were intentionally removing it for your setup.

In fact, I tried that command sequence on my own shell before posting it without any problems. So I assume you took out the export to prevent that PATH from being inherited by child processes.

If you did have a problem with it, I'd be interested to know what it was.
 
Old 04-21-2005, 01:53 AM   #7
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Original Poster
Rep: Reputation: 15
Just to be clear, you did answer my ?

however, when I put exactly what you had type

export PATH=$(cat path_file)

it did not work, but when I

PATH=$(cat path_file)

it worked fine, and then of course I was able to export it. Weird huh? I am using FC2 if that matters any.
 
Old 04-21-2005, 02:23 AM   #8
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Well, what I was getting at was: how do you know the export didn't work? Was an error displayed? Was the wrong value shown when you did the echo? Was there some other indication?

I was just saying that the export command worked without a problem on my system (I usually try out commands before I suggest them). Essentially, what happens with that command is this:
  • The text inside the $() is interpreted as a command to execute
  • The command and the surrounding $() are replaced with the command's output
  • The command's output is assigned to the PATH variable
  • The export causes PATH to become an environment variable
So, to my knowledge, the export command should not have any influence on the assignment to PATH. If it's not working, then that might mean there is a case I should be aware of, or possibly a flaw in my logic.

It's not a huge deal. You say it's working if you just add another step; inconvenient, but workable. I'm just curious about it is all.
 
Old 04-21-2005, 12:58 PM   #9
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Original Poster
Rep: Reputation: 15
it returned an error of "command not found" beleive it or not.

Oh, wait, Duh, I think I just realized what it was. Since there was nothing in my PATH at the time I ran this, and I didn't type in the full path to the export statement, that is why it gave me command not found. Duh!

THX!
 
  


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
Adding directories to the PATH statement kaplan71 Slackware 2 09-02-2004 03:57 PM
please tell me if my path statement is correct on RH 7.3 ergo_sum Linux - Newbie 9 12-12-2003 11:41 PM
PATH statement editing? cottonmouth Linux - General 2 08-17-2003 08:00 PM
need perl fuction like c #include statement for header file mrtwice Programming 5 06-19-2003 02:42 PM
What file hold the PATH statement billkris Linux - General 7 02-11-2003 10:30 PM


All times are GMT -5. The time now is 07:41 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration