Bug 78029

Summary: check for adding to PATH in /etc/profile can fail
Product: [Retired] Red Hat Linux Reporter: Kjetil T. Homme <kjetilho>
Component: setupAssignee: Bill Nottingham <notting>
Status: CLOSED CURRENTRELEASE QA Contact: David Lawrence <dkl>
Severity: low Docs Contact:
Priority: medium    
Version: 8.0CC: rvokal
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-09-23 05:35:35 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kjetil T. Homme 2002-11-17 23:10:47 UTC
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
    PATH=/sbin:$PATH
fi

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:
Always

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
    do
        case :$PATH: in
            *:$elem:*) : ;; # already in PATH, do nothing
            *)         PATH="$elem:$PATH" ;;
        esac
    done
}

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


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 05:35:35 UTC
This is fixed in current packages.