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

Reported by:	lme
This commit is contained in:
Jilles Tjoelker 2012-02-11 21:06:45 +00:00
parent c21ae3a403
commit c0b3cf0676
2 changed files with 18 additions and 8 deletions

View File

@ -231,7 +231,9 @@ hashcmd(int argc __unused, char **argv __unused)
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 __unused)
&& 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;
}

View File

@ -0,0 +1,6 @@
# $FreeBSD$
exec 3>&1
m=`hash nosuchtool 2>&1 >&3`
r=$?
[ "$r" != 0 ] && [ -n "$m" ]