Author: jilles
Date: Sat Feb 11 21:06:45 2012
New Revision: 231535
URL: http://svn.freebsd.org/changeset/base/231535

Log:
  sh: Make 'hash' return 1 if at least one utility is not found.
  
  Reported by:  lme

Added:
  head/tools/regression/bin/sh/builtins/hash4.0   (contents, props changed)
Modified:
  head/bin/sh/exec.c

Modified: head/bin/sh/exec.c
==============================================================================
--- head/bin/sh/exec.c  Sat Feb 11 20:47:16 2012        (r231534)
+++ head/bin/sh/exec.c  Sat Feb 11 21:06:45 2012        (r231535)
@@ -231,7 +231,9 @@ hashcmd(int argc __unused, char **argv _
        int verbose;
        struct cmdentry entry;
        char *name;
+       int errors;
 
+       errors = 0;
        verbose = 0;
        while ((c = nextopt("rv")) != '\0') {
                if (c == 'r') {
@@ -254,19 +256,21 @@ hashcmd(int argc __unused, char **argv _
                 && cmdp->cmdtype == CMDNORMAL)
                        delete_cmd_entry();
                find_command(name, &entry, DO_ERR, pathval());
-               if (verbose) {
-                       if (entry.cmdtype != CMDUNKNOWN) {      /* if no error 
msg */
-                               cmdp = cmdlookup(name, 0);
-                               if (cmdp != NULL)
-                                       printentry(cmdp, verbose);
-                               else
-                                       outfmt(out2, "%s: not found\n", name);
+               if (entry.cmdtype == CMDUNKNOWN)
+                       errors = 1;
+               else if (verbose) {
+                       cmdp = cmdlookup(name, 0);
+                       if (cmdp != NULL)
+                               printentry(cmdp, verbose);
+                       else {
+                               outfmt(out2, "%s: not found\n", name);
+                               errors = 1;
                        }
                        flushall();
                }
                argptr++;
        }
-       return 0;
+       return errors;
 }
 
 

Added: head/tools/regression/bin/sh/builtins/hash4.0
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/hash4.0       Sat Feb 11 21:06:45 
2012        (r231535)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+exec 3>&1
+m=`hash nosuchtool 2>&1 >&3`
+r=$?
+[ "$r" != 0 ] && [ -n "$m" ]
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to