Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
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.
SPATH shows all the paths that any executable file in there can be run from any directory. If correct, how can I add a new path (directory) to the list? There must be a file somewhere, I just don't remember where was it?
And, how can I add the current directory (.) so that every time I do not have to type ./ ?
this way it will check the directory your in first and will set your $PATH every time you log in.
to add another path do a similar thing:
export PATH=$PATH:newpath1:newpath2
the semi-colon is the delimeter to clarify when a new path starts and ends. You can also run this from command line to set for your current shell environment however this will be reset when you open a new shell.
The variable name is PATH. You tell the shell it is a variable by prepending it with the $ so it becomes $PATH.
To add items to existing PATH:
PATH=$PATH:/new/path/dir
This puts /new/path/dir into your PATH after whatever was already there. The colon ( is the separator it uses.
You can see value of PATH by typing:
echo $PATH
PATH is typically started within your /etc/profile or /etc/bashrc. You could see multiple lines adding to it there. It is then added to by your user's $HOME/.profile, $HOME/.bashrc and/or $HOME/.bash_profile.
Typically you'd want to edit the file in $HOME as that affects. ($HOME by the way is another variable = your home directory).
echo $PATH shows about 10 different paths on my machine, but they are not in /etc/profile, nor /etc/bash.bashhrc (I don't have /etc/bashrc). As a matter of fact, these 2 files are more like a program with lots of "if" command.
So, these specified paths have to be somewhere else. Any idea?
You didn't mention the files in $HOME of which I spoke.
When you login depending on shell it FIRST loads in /etc/profile or /etc/bashrc THEN loads in whatever is in the $HOME of the user that logged in.
Also if any of those files invoked other files then it would load in variables specified in that. An example is that some people have $HOME/.bash_profile invoke $HOME/.bashrc. In that case it would load:
/etc/bashrc
$HOME/.bash_profile
$HOME/.bashrc
It can also load in files we don't know about e.g. /usr/local/bin/somescript.sh (not a real name - just an example).
That script could also be loading in other files we don't know about.
Look at $HOME for the appropriate user. Notice "." in the names above - that is a "hidden" file so doesn't show up with "ls -l" - you have to do "ls -la".
Thanks for all the information. By "echo $HOME", I get a list of a number of files, including those ones starting with ".", such as .profile and .bashrc. I opened them both, but I still don't see the directories which are listed by "echo $PATH". They must be somewhere, and the reasonable place is either .profile (or /etc/profile) or .bashrc (or /etc/bashrc; as I said before I don't have /etc/bashrc, but I do have /etc/bash.bashrc).
Any idea how the specified PATHs are working on my machine?
By the way, in /usr/local/bin/ , I don't see any file with "sh" extension (ie, *.sh).
this way it will check the directory your in first and will set your $PATH every time you log in.
Again, i've got to say this is really really nasty practise. a command should run from anywhere when an absolute or relative path is not specified. running "mycommand" in your home directory may run /home/user/mycommand but running it whilst in /tmp may fall back to /usr/bin/mycommand. this is really really nasty...
I'd suggest you read the man pages for "login" and "bash".
When you login you invoke a file in /etc first (which one it is depends on your shell)). THAT file may contain directives to "source" other files which could be named ANYTHING. The sourced files may in turn invoke files named ANYTHING. After the /etc (which is "global" meaning all users get them) it then goes to the files in $HOME of the specific user to invoke "local" files. These files can also source in other files which could be named anything. The sourced in files can also source in other files and so on.
You have to look at everything that is occurring when you login. There is no way anyone else can tell you what you are getting for PATH without knowing all the files you're invoking/sourcing and they are not the same on every system.
I once had a system where /etc/profile was fairly simple but .profile in $HOME invoked a script which in turn invoked another script which sourced in a specialized profile which invoked yet another script. Either you're not reading your files correctly or they're doing something similar to this because someone else set them up for you. If the latter you might want to ask that person.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.