Package: bash
Version: 3.0-5
Severity: normal

Please consider the following sequence of commands which illustrates
that "command -v foo" prints the name of the first executable file "foo"
it finds on the PATH, failing which it prints the first non-executable
file "foo" it finds on the PATH.

[EMAIL PROTECTED]:~$ echo $PATH
/home/jdthood/bin:/usr/local/bin:/bin:/usr/bin:/usr/bin/X11:/usr/games
[EMAIL PROTECTED]:~$ which foo
[EMAIL PROTECTED]:~$ command -v foo
bash: command: foo: not found
[EMAIL PROTECTED]:~$ touch /home/jdthood/bin/foo
[EMAIL PROTECTED]:~$ ls -l /home/jdthood/bin/foo
-rw-r--r--  1 jdthood jdthood 0 2005-01-18 10:40 /home/jdthood/bin/foo
[EMAIL PROTECTED]:~$ which foo
[EMAIL PROTECTED]:~$ command -v foo
/home/jdthood/bin/foo
[EMAIL PROTECTED]:~$ sudo touch /usr/local/bin/foo
[EMAIL PROTECTED]:~$ which foo
[EMAIL PROTECTED]:~$ command -v foo
/home/jdthood/bin/foo
[EMAIL PROTECTED]:~$ ls -l /usr/local/bin/foo
-rw-r--r--  1 root staff 0 2005-01-18 10:41 /usr/local/bin/foo
[EMAIL PROTECTED]:~$ sudo chmod ugo+x /usr/local/bin/foo
[EMAIL PROTECTED]:~$ ls -l /usr/local/bin/foo
-rwxr-xr-x  1 root staff 0 2005-01-18 10:41 /usr/local/bin/foo
[EMAIL PROTECTED]:~$ which foo
/usr/local/bin/foo
[EMAIL PROTECTED]:~$ command -v foo
/usr/local/bin/foo


Because of this behavior, "command -v foo" alone cannot be used to tell
whether or not there is an executable program named 'foo' on the PATH.
One has to do something like this to work around the problem:

   if CMD="$(command -v foo 2>/dev/null)" && [ -x "$CMD" ] ; then
      ...


-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing'), (50, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.9
Locale: [EMAIL PROTECTED], [EMAIL PROTECTED] (charmap=ISO-8859-15)

Versions of packages bash depends on:
ii  base-files                  3.1.2        Debian base system miscellaneous f
ii  libc6                       2.3.2.ds1-20 GNU C Library: Shared libraries an
ii  libncurses5                 5.4-4        Shared libraries for terminal hand
ii  passwd                      1:4.0.3-30.7 Change and administer password and

-- no debconf information


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to