bug-bash
[Top][All Lists]
Advanced

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

"type ls unexisting" gives 0 exit status


From: stephane_chazelas
Subject: "type ls unexisting" gives 0 exit status
Date: Fri, 10 Nov 2006 12:49:53 +0000

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2
uname output: Linux sc 2.6.19-rc1 #5 PREEMPT Fri Oct 6 19:52:16 BST 2006 i686 
GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.1
Patch Level: 17
Release Status: release

Description:
        Hi

        $ bash -c 'type ls foo; echo "$?"'
        ls is /bin/ls
        bash: line 0: type: foo: not found
        0

        http://www.opengroup.org/onlinepubs/009695399/utilities/type.html
        suggests that the exit status should be >0 in that case which is
        the case with other shells (ash, zsh, pdksh, ksh93).

        Same for command -v ls foo
        but command -v is not meant to accept more than 1 arg according
        to POSIX. But you may want to change that as well for
        consistency.

Repeat-By:
        bash -c 'type ls foo; echo "$?"'
        last line of output is "0" instead of "1" or "127".

Fix:

--- /home/chazelas/tmp/type.def~        2005-08-24 13:38:34.000000000 +0100
+++ type.def    2006-11-10 12:43:34.000000000 +0000
@@ -108,14 +108,14 @@
 type_builtin (list)
      WORD_LIST *list;
 {
-  int dflags, successful_finds, opt;
+  int dflags, unsuccessful_finds, opt;
   WORD_LIST *this;
 
   if (list == 0)
     return (EXECUTION_SUCCESS);
 
   dflags = CDESC_SHORTDESC;    /* default */
-  successful_finds = 0;
+  unsuccessful_finds = 0;
 
   /* Handle the obsolescent `-type', `-path', and `-all' by prescanning
      the arguments and converting those options to the form that
@@ -181,13 +181,13 @@
       if (!found && (dflags & (CDESC_PATH_ONLY|CDESC_TYPE)) == 0)
        sh_notfound (list->word->word);
 
-      successful_finds += found;
+      unsuccessful_finds += !found;
       list = list->next;
     }
 
   fflush (stdout);
 
-  return ((successful_finds != 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
+  return ((unsuccessful_finds == 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
 }
 
 /*




reply via email to

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