Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 78029 - check for adding to PATH in /etc/profile can fail
Summary: check for adding to PATH in /etc/profile can fail
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: setup
Version: 8.0
Hardware: All
OS: Linux
medium
low
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-11-17 23:10 UTC by Kjetil T. Homme
Modified: 2014-03-17 02:32 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-09-23 05:35:35 UTC


Attachments (Terms of Use)

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.


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