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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-19-2005, 10:37 PM
|
#1
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Rep:
|
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!
|
|
|
04-20-2005, 04:46 AM
|
#2
|
Member
Registered: Aug 2003
Location: Melbourne Australia
Distribution: Fedora Core 4
Posts: 184
Rep:
|
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
|
|
|
04-20-2005, 03:12 PM
|
#3
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Original Poster
Rep:
|
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.
|
|
|
04-20-2005, 09:23 PM
|
#4
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
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.
|
|
|
04-20-2005, 10:50 PM
|
#5
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Original Poster
Rep:
|
ah ha! I was missing the () around cat path_file
THX! It worked (but I had to take out the export).
|
|
|
04-20-2005, 11:00 PM
|
#6
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
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.
|
|
|
04-21-2005, 01:53 AM
|
#7
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Original Poster
Rep:
|
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.
|
|
|
04-21-2005, 02:23 AM
|
#8
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
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.
|
|
|
04-21-2005, 12:58 PM
|
#9
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Original Poster
Rep:
|
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!
|
|
|
All times are GMT -5. The time now is 11:31 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|