[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Minor change/addition to /bin/sh -- for review
I have just committed a "try it for a week, see if you like it,
if you don't return it for a full refund" type change to the
shell's builtin "hash" command.
The man page changes have not been made yet, and might not be if
people (that's you!) don't like it how it might be now.
When done, what the man page section will say (not quite like this,
as it has to fit within sh(1) ) is something like
hash [-bcfrsuv] [--] [command ...]
If the -r flag is given, then before any other action,
the shell's command hash table is cleared of all utilities.
Functions and special builtin commands remain.
Other builtin commands might be removed, in circumstances
that you really don't want to know about and will not
be described here.
After this, if no command args are given, then the contents
of the hash table are writen to stdout. With -v, all entries
of the hash table are written, with information on what kind of
entry (builtin, special builtin, function, or utility) the
entry refers to. With functions, a (perhaps abbreviated) listing
of the function code is also given. Without the verbose flag,
only utilities in the hash table are listed, and only their path names.
A path name can be followed by a '*' if the shell believes
verification of the path is required - this usually means that
a cd command has been performed since the entry was made in the
hash table (and so if there were any relative paths in $PATH,
a new entry may have appeared ahead of the one previously found.)
With command args, those commands are first removed from the
hash table if present, and if a utility or normal builtin, and
then searched for in the list of internal builtins, and in $PATH,
and when found, are entered back into the hash table. When the
verbose (-v) flag is set, entries added are listed (in the same
verbose format as above.)
[ So far that is essentially the old hash command, and if just used
that way, there is very little change, the new part follows...]
The -b, -c (or -u, which are alternative flags for the same purpose),
-f, and -s flags can be used to limit output to normal builtins (-b),
commands or utilities (different names for the same thing) (-c or -u)
functions (-f), and special builtins (-s). One or more of these flags
can be given.
When those flags are used without command args, the output contains
entrfies for the type(s) requested (in verbose format is -v is also
With command args, the hash command will not delete an entry from the
table (and hence will not replace it with possibly updated information)
if the command is not one of the types specified.
If none of the -b -c (or -u) -f or -s flags are set, the default is
all of them - except when no commands are given, in which case the
default is -c, but only when -v is also given (this is for compibility
with the way the hash command behaved previously.)
Removing a function from the has table is done by "unset -f name",
after which the function no longer exists, unless redefined.
Special builtins cannot be rmeoved. Regular builtins can, though
there is little point, and the method is left as an exercise for
the source code reader.
brief listing (just paths) of commands (utilities)
in the hash table
long listing of all hash table entries
list names of defined functions
same as just "hash" as is "hash -u"
clear all commands (utilities) from has table
(and sometimes, normal builtins as well).
remove gcc from has table if it was there,
search PATH for it, and add it to the hash table.
hash -v gcc
As above, but if gcc is successfully re-added,
list its entry (in verbose mode).
hash -b test
similar, but do nothing if the test found is
not a builtin.
hash -v -bsf
verbose listing of everything except normal commands.
remove foobar from the hash table (if a command),
then search PATH for it, and add it if found.
(If not found, that will be rpeorted.)
The exit status of the hash command is 0 unless an unknown option is given.
--- --- ---
So, if you test or run current, give it a try, tell me what you think
(or give opinions, or ask questions, based solely upon this e-mail if
If this seems like a bad idea, no problem reverting it (it is really a
relatively small change.)
ps; note that the description varies a little from the current man page
description of the has command. That's because the current description
is not quite correct... That will get fixed if we decide to go back to
the old hash command.
Main Index |
Thread Index |