On Monday November 12 2012 00:06, Adam wrote: > I ran across a strange inconsistency today. What should > > su -l -c 'echo $PATH' > > return when run by an ordinary user (who happens to know the root > password) at the bash prompt? Under Mandriva and CentOS it returns the > user's path, but under Debian it returns root's path. I don't > understand the inconsistency or which response is correct, but that > would seem to make some shell scripts non-portable. > > Adam
So far no one has mentioned this but there are a few reasons why there might be problems with PATH not being what you would expect. The following is for the bash shell. Process may be different for cshell or zsh. First is how shells are started. There are three types of shells: 1. Login shell 2. Normal shell 3. Interactive shell The login shell starts by running /etc/profile. This is where you would normally find a setting for PATH. There may be basic settings here or there may be tests for the userid and if root a special PATH would be set. What is here will completely replace any PATH setting that may exist. Also there may be calls to the user's ~/.profile, ~/.bash_profile, ~/.bash_login, and/or ~/.profile. In some cases /etc/bashrc may also be called. Including the previous files the user's ~/.bashrc would be called. The normal and interactive shells would call the user's ~/.bashrc. This file normally would invoke other files for proper setup. Now for the command su -l -c 'echo $PATH'... The single quotes around the echo would keep command line substution of $PATH from occurring so the $PATH will not be resolved until the su shell is running. The command su is being run in the user's shell so the $PATH is the user's PATH and unless changed that is what the echo would display. The argument -l requests that a login shell be used when switching to the root userid. This would invoke the above mentioned files if they are found. Having the PATH show the user's settings sounds like the PATH was not changed when the su command was run. This is not good. I hope this sheds some light on what might be happening. Check all of the above files and see if there is something wrong with where PATH is being set. To see which files get control and in which order you could place echos in the files. Regards, Tim _______________________________________________ Mid-Hudson Valley Linux Users Group http://mhvlug.org http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug Upcoming Meetings (6pm - 8pm) Vassar College Dec 5 - SysAdmin Panel Jan 9 - High Performance Computing Feb 6 - February Meeting
