LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Where is PATH originally set (https://www.linuxquestions.org/questions/linux-newbie-8/where-is-path-originally-set-547698/)

mjguillo 04-20-2007 04:47 PM

Where is PATH originally set
 
I have a question as to where the PATH variable is originally set. All of the posts I have seen about editing the PATH variable include something like

PATH=$PATH:\newstuff
export PATH
But this just appends \newstuff to to the already existing path variable. It has to be set somewhere originally, but I can't seem to find where.

I am using the bash shell.

Can anybody help me out?
Thanks
mjguillo

druuna 04-20-2007 05:14 PM

Hi,

This depends a bit on how your distro is set up.

If you don't use pam it's set in this file: /etc/login.defs. The options are ENV_SUPATH and ENV_PATH
If you do use pam it probably in this file: /etc/security/pam_env.conf. The option is PATH

Hope this helps.

Oupa 05-09-2007 09:45 AM

PATH variable
 
One of the sytem wide startup files that sets the PATH is /etc/profile.
/etc/bashrc sets aliases.
Oupa.

druuna 05-09-2007 09:58 AM

Hi,

@Oupa: /etc/profile and/or /etc/bashrc are used to change and or add to the PATH variable. The questions was were it was originally set. This is not done in either of the files you mention. If you remove all PATH settings in all login files (including those that are in your homedir files), you are still presented with a basic PATH setting.

Hope this clears things up.

Oupa 05-10-2007 12:50 AM

PATH Variable
 
Hi, it appears that we have still not solved the origin of the PATH. I have checked the /etc/login.defs file and find no reference to PATH. Quoting from the Red Hat Linux Bible:
----------------------------------------
/etc/profile - This file sets up the user environment information for every user. It is executed when you first log in. This file provides values for your path, as well as setting environment variables for such things as the location of your mailbox and size of history file. Finally, /etc/profile gathers shell settings from configuration files in the /etc/profile.d directory.
----------------------------------------
I find no reference to PATH in the files in /etc/profile.d directory. I therefore assume that the RHL Book is correct and that it is set in /etc/profile, at least until someone proves conclusively that it originates elswhere. Oupa.

druuna 05-10-2007 01:34 AM

Hi,

I did mention 2 places, depending on your setup. You seem to have overlooked pam....

jschiwal 05-10-2007 01:45 AM

You could grep for 'PATH=' in /etc/. Look in /etc/rc.sysinit if you have it.
There may be something in /etc/profile.d/ as well.

druuna 05-10-2007 02:13 AM

Hi,

Some extra, login.defs related, info:

From login.defs:
Quote:

#
# *REQUIRED* The default PATH settings, for superuser and normal users.
#
# (they are minimal, add the rest in the shell startup files)
ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
From the shadow suite:
Quote:

ENV_SUPATH is no longer supported. You must create a valid /root/.bashrc file to provide a modified path for the super-user.
BTW: A Red Hat bible isn't leading, it tells you how Red Hat does things.......

Oupa 05-11-2007 02:38 AM

PATH origin
 
Hi mjguillo and guys, my apoligies for complicating what should have been a simplistic answer. Perhaps I should merely have stated the /etc/profile is the ideal place to modify the PATH globally for the bash shell. As the guys have pointed out other application software can also modify the value of PATH.
Below is a more technical explanation of how the PATH originates:
------------------------------------------------

Init:
Init is a parent process for all the other processes of the system. Other processes inherit environment of the init process and the path is the init path in the rare case that no other path is set.
The 'init path' is fixed in the source of the init program and it is:
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin

Login:
In text console there is a getty program waiting for user login. It writes 'login:' and other messages. It is working in init environment. When getty gets user to log in to the system, it invokes the 'login' program. This program sets the user environment and invokes the shell.
Login program sets path as defined in /usr/include/paths.h. This 'login path' is different for root users and other users.
for common users (_PATH_DEFPATH):
/usr/local/bin:/usr/bin:/bin:.
for root (_PATH_DEFPATH_ROOT):
/sbin:/bin:/usr/sbin:/usr/bin

Strategies to get the same path for all the users:
The most important settings is possible to set in the global shell initialization files for login shells: /etc/csh.login for tcsh and /etc/profile for bash.
Exceptions that do not get the right path from these files are rsh commands, ssh commands, menu items from X window manager that do not explicitly start login shell, commands invoked from inittab, cron jobs, daemons jobs like magic filters started from lprd, WWW CGI scripts, and so on.
----------------------------------------------------
Oupa.

taxtropel 05-11-2007 03:12 AM

Why?
 
The origin of PATH variable it totaly distribution dependant.

The real question is: "Why does it matter?"

You should not modify the Original PATH, but rather you should add on to the end of the path (or beginning).

As stated by many others this can be changed in a multiple of locations.

remember ogres...err...linux is like an onion, it's all about the layers.

If you don't like the way your distribution is setup, then try another or better yet make your own... LFS
mmm...LFS: it's like eating doughnuts...only more stressful and labor intensive.

OH and for a good book about linux, forget the "Red Hat Bible"
and get "Running Linux"


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