This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 78029 - check for adding to PATH in /etc/profile can fail
check for adding to PATH in /etc/profile can fail
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: setup (Show other bugs)
8.0
All Linux
medium Severity low
: ---
: ---
Assigned To: Bill Nottingham
David Lawrence
:
Depends On:
Blocks:
  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:
Environment:
Last Closed: 2004-09-23 01:35:35 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
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
    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 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.