Bug 78029 - check for adding to PATH in /etc/profile can fail
check for adding to PATH in /etc/profile can fail
Product: Red Hat Linux
Classification: Retired
Component: setup (Show other bugs)
All Linux
medium Severity low
: ---
: ---
Assigned To: Bill Nottingham
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2002-11-17 18:10 EST by Kjetil T. Homme
Modified: 2014-03-16 22:32 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-09-23 01:35:35 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Kjetil T. Homme 2002-11-17 18:10:47 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003

Description of problem:
/etc/profile includes code like
if [ `id -u` = 0 ] && ! echo $PATH | /bin/grep -q "/sbin" ; then

this will fail to add /sbin if, say, /usr/local/sbin is already in $PATH.  it
also requires /usr/bin to be in $PATH a priori.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. set PATH to /usr/local/sbin:/bin
2. run bash

Actual Results:  bash: id: command not found
bash: id: command not found
bash: id: command not found
bash: [: too many arguments
bash: tput: command not found
bash: tput: command not found
bash: wc: command not found
bash: [: : integer expression expected
bash: dircolors: command not found

Additional info:

I suggest to replace the code with something like this:

prepend_path() {
    for elem
        case :$PATH: in
            *:$elem:*) : ;; # already in PATH, do nothing
            *)         PATH="$elem:$PATH" ;;

prepend_path /usr/X11R6/bin /bin /usr/bin /usr/local/bin
if [ $EUID = 0 ]
    prepend_path /sbin /usr/sbin /usr/local/sbin

this method uses no external processes, so it should be a tiny bit faster. 
$EUID is specific to bash, so you may not be able to use that, and have to fall
back on id -un.
Comment 1 Bill Nottingham 2004-09-23 01:35:35 EDT
This is fixed in current packages.

Note You need to log in before you can comment on or make changes to this bug.