bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash should not alter PATH with 'command -p'


From: sdowdy
Subject: bash should not alter PATH with 'command -p'
Date: Thu, 28 May 2015 13:59:01 -0600

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib  -D_FORTIFY_SOURCE=2 -g 
-O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall
uname output: Linux resonance 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 
(2015-04-24) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.3
Patch Level: 30
Release Status: release

Description:

NOTE: admittedly, i did not want to spend many hours researching this if it's 
already been brought up, because searching for the unfortunately named 
'command' (the name of the builtin) gives waaaaaaaaaaaay too much noise to 
filter through.  I still believe it's worth restating anyway, if only to help 
document the wigginess of the downstream effects of something like the 
'aptitude' function redefinition below, and any child-processes launched by a 
"found" command.

'command -p' 
    Ref:http://pubs.opengroup.org/onlinepubs/009696699/utilities/command.html

    "... -p Perform the command search using a default value for PATH that is 
guaranteed to find all of the standard utilities. ..."

    The way i read that is:
        "search for a command only in a default PATH location, then invoke it 
(not altering user environment in the process)"
    The way 'bash' seems to be looking at that is:
        "set the user's PATH to a default value, then invoke"

This caused me much grief with:

    is_debug() { [ "${DEBUG:-0}" != 0 ] ;}
    # suppress (quiet=2) if we aren't in debug mode
    aptitude() { if is_debug; then command -p aptitude "$@"; else command -p 
aptitude -q=2 "$@"; fi ;}

producing the following failure mode:
    # aptitude purge packagekit-tools debsums devscripts unattended-upgrades
    No packages will be installed, upgraded, or removed.
    0 packages upgraded, 0 newly installed, 0 to remove and 16 not upgraded.
    Need to get 0 B of archives. After unpacking 0 B will be used.
    dpkg: warning: 'ldconfig' not found in PATH or not executable
    dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
    dpkg: error: 2 expected programs not found in PATH or not executable
    Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and 
/sbin
    E: Sub-process /usr/bin/dpkg returned an error code (2)
    Failed to perform requested operation on package.  Trying to recover:
    dpkg: warning: 'ldconfig' not found in PATH or not executable
    dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
    dpkg: error: 2 expected programs not found in PATH or not executable
    Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and 
/sbin

Note that not all of these shells below claim to be POSIX compliant, but i 
would argue the fact that only 'bash' is altering the PATH with 'command -p' 
and that the language in the POSIX spec seems pretty clear about only 
performing "the command search" using a default PATH, that 'bash' should NOT be 
altering the user's PATH at all.

    $ for shell in bash dash ksh mksh zsh; do echo "[$shell]"; /bin/${shell} -c 
'env | grep ^PATH; command -p env | grep ^PATH'; done
    [bash]
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
--> PATH=/bin:/usr/bin
    [dash]
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
    [ksh]
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
    [mksh]
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
    [zsh]
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
    
PATH=/opt/bin:/opt/sbin:/usr/local/jdk:/home/sdowdy/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin

not even in strict POSIX mode:
    $ bash --posix
    bash-4.3$ command -p env | grep ^PATH
    PATH=/bin:/usr/bin

Repeat-By:
    See Above



reply via email to

[Prev in Thread] Current Thread [Next in Thread]