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

Bug#291026: 9.3.3.2 "command -v" example needs tweaking



Package: debian-policy
Version: 3.6.1.1
Severity: minor

Section 9.3.3.2 gives this as an example of how to check for the
availability of invoke-rc.d:

>    if command -v invoke-rc.d >/dev/null 2>&1; then

1. It would be helpful to mention that "command -v" is not POSIX and
   that therefore, to be consistent with section 10.4, this example
   should only be followed in scripts headed with "#!/bin/bash".

   If #218530 is ever implemented then this restriction can be
   dropped.

2. "command -v" in bash 3.0-5 sometimes prints pathnames of files
   on the PATH that aren't executable.  To work around this, the
   example could be changed to something like this:

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

Discussion
----------
I actually think that issue #2 is a bug in bash. Consider the following
sequence of commands which illustrate 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.  What sense does that make?  If people agree then I'll
file a bug report against bash.

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


-- 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: LANG=en_IE@euro, LC_CTYPE=en_IE@euro (charmap=ISO-8859-15)

-- no debconf information



Reply to: