NetBSD-Bugs archive

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

Re: bin/56491: /bin/sh hash command "hash foobar" says foobar not found, and exit(1)



The following reply was made to PR bin/56491; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/56491: /bin/sh hash command "hash foobar" says foobar not found, and exit(1)
Date: Sun, 14 Nov 2021 08:41:20 +0700

 For this (see the original PR for the details) I am considering having
 the best of all worlds (since it is so simple - the change is truly trivial).
 
 That is, make the default be like bash/dash/ ... (everything
 not a ksh variant) which makes "hash foobar" generate an error
 just like now, but will exit 1 instead of 0 if any command to
 be added to the hash table is not found.   That takes adding
 one test to see if the command was found, and making the return
 value be a variable rather than const 0.
 
 Then add a -e option (no errors) to make it work the ksh way,
 which means suppressing the error message (one arg to the lookup
 routine changes value), and continue to exit(0).
 
 And since all this is so easy, add a -q (quiet) option which will
 suppress the "not found" error message, but still result in an
 exit(1) in the case that a command named was not found.  This is
 similar to hash command 2>/dev/null except that any other errors would
 still appear on stderr, only the "command not found" would be skipped.
 
 Then, just because it is so simple, make -e invert the sense of
 whatever -q gets set to, then use just -q to decide whether to suppress
 the error message internally (and -e just for the exit status).
 This makes hash -e do what we want (-q is implicitly set to suppress
 the error), and hash -eq return to what NetBSD "hash" command has been
 doing forever (generate the not found error message (as -q gets inverted
 by -e), but exit(0)).   I don't see this being very useful, but it does
 provide a backwards compat variant, and is cost free.
 
 The most difficult part of all of this is the man page update - and not to
 document these new options, but, to document the other options that the
 hash command has had for quite a while now, but never got documented.
 
 Any comments before I commit this?
 
 kre
 
 


Home | Main Index | Thread Index | Old Index