-
December 14th, 2001, 10:21 PM
#1
Linux "path"
I'm trying to find the linux equivalent of the ms-dos path variable, could anyone tell me how I might locate and modify it?
See when I compile code into an executable, I have to do one of two things to run it. Copy it into the /bin directory, or reference it by the full pathname. It's not a huge inconvenience to type ./a.out but I'd like to know how I can get the OS to search either the current directory, or other directories besides /bin when I call an executable file. I'm running redhat 7.1 and mandrake 8.0, I'm hoping it's a similar solution on both systems. Thanks.
-
December 14th, 2001, 10:29 PM
#2
Hi Shkuey,
Give a try to echo $PATH. You should be able to find it in your .bash_profile (assuming you are using the Bash shell -- use the ls -a and look for a file with the word profile in it) and modify it with your favourite editor.
It's a good idea to create a bin directory in your home directory and then add it. Remember that : is the separator for PATH locations and its recommended that you end your PATH with :.. This means the last place that Linux will look is the current working directory. 
Hope this helps.
-
December 14th, 2001, 11:33 PM
#3
Senior Member
It's a good idea to create a bin directory in your home directory and then add it. Remember that : is the separator for PATH locations and its recommended that you end your PATH with :.. This means the last place that Linux will look is the current working directory.
It is a good idea for normal users, but it is generally NOT what you want to do with root's PATH variable. If your system has been compromised, someone could plant a command (like a copy of "ls") in a directory that you may use as root. If you run that command while in that directory and you have the "." in your path, you may find that it will install a "root kit." I know, I know... That's why it's at the END of the PATH, but it's still not a good idea. Just my two cents.
Happy Hacking
-----------------------------------------------------
Warfare is the Way of deception.
-Sun Tzu \"The Art of War\"
-
December 16th, 2001, 10:49 AM
#4
Junior Member
Linux Path
In Linux exist the variable name PATH in upper that define wehat is the path. In the prompt of linux put set, if dont see all in the screen you can put set |more, and look for a variable named PATH. More easy put echo PATH and you will see how look for the executables. If you want to put a new PATH is very easy if you usa a bash shell you have to edit .bashrc and put this new line:
PATH=$PATH:MY_DIRECTORY
for example:
PATH=$PATH:/home/shkuey
and then the files that is on your home directory will be executable.
If you use other shell diferent of bash you have to edit .profile that is in your home directory and put the same line. To see the changes you have to exit and enter. Bye
Hide your face forever
dream and search forever
night and night you feel nothing
there\'s no way outside of my land
Open your eyes, open your mind ...
-
December 18th, 2001, 07:55 PM
#5
On unix, you generally find the PATH being declared in a file called /etc/PATH, readonly by root that's read by the shell upon login. You can see if that's in your distro of linux or you can do what the others have already stated, that being editing (go vi!) your .profile or .bash_profile or you could export a new
path with the following:
$ echo $PATH
<path here>
$ export PATH=$PATH:<add in path extension here>
$ echo $PATH
<path with additions here>
This will add those extensions to your path ONLY for the duration of that shell. Once you exit, everything's cleaned up and those changes won't be permanent. This is a good thing though because you'll learn that with shell scripts, you'll want to 'jail' a shell script so that it's limited to what can be done, in the event it gets taken over by a "malicious" (Geez, hasn't the media overused that word) user.
$ echo $PATH
<path listed here with all kinds of directories>
$ cat foo
#!/bin/sh
PATH=/bin:/usr/bin
echo $PATH
$ ./foo
<path with only /bin and /usr/bin listed here>
It's a security thing mainly but it is useful. If you 'export' a path in a shell script, your remaining shell session will have said path in
the PATH variable...not really recommended.
Hope this helps.
We the willing, led by the unknowing, have been doing the impossible for the ungrateful. We have done so much with so little for so long that we are now qualified to do just about anything with almost nothing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|