bug-bash
[Top][All Lists]
Advanced

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

hash -d 0/1 and other hash stuff


From: Mike Jonkmans
Subject: hash -d 0/1 and other hash stuff
Date: Wed, 6 Sep 2023 16:55:52 +0200

The following 'hash -d' statements have different exit statuses.

        bash --noprofile --norc -c \
                'hash -d ls; echo $?' ## 0
        bash --noprofile --norc -c \
                'cat </dev/null; hash -d ls 2>/dev/null; echo $?' ## 1

This depends on a hashable command being given (e.g. cat </dev/null)
prior to the 'hash -d'.

Bash' documentation says:
        "The return status is true unless a name is not found ..."

So, I'd say, both commands should have exit status 1 - as 'ls' was not hashed.

POSIX (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/hash.html)
only has -r as option.

FWIW: 
https://github.com/search?q=language%3AShell+content%3A%2F%28%5E%7C%5B%5B%3Ablank%3A%5D%5D%29hash%5B%5B%3Ablank%3A%5D%5D-d%2F+NOT+zsh&type=code

Simple patch attached, making 'hash -d ls' exit with 1 in the first case also.
But ...


Questions

1) Why is 'hash -d x' exiting with 1 at all? If the goal is to `unhash x',
'hash -d x' will do the job. Even if x was not hashed at all.
But I am not sure that such a change is feasible (backwards compatible).


2) 'hash x' and 'hash -l x' seem to do the same
(i.c. path search and add to hash if found).
It would be more useful to let 'hash -l x' give the 'hash -l' output for x.
Moreover, I find it unexpected that 'hash -l x' adds x to the hash.
A quick look on github, shows no use of 'hash -l x',
so changes might be ok.

'hash -lt x' outputs what I would have expected 'hash -l x' to do.
Note that 'hash -lt x' doesn't add x to the hash (unexpected).


3) These option combinations should error/exit 1:
Ignoring the '-p path' part:
        hash -p path
        hash -p path -t name
        hash -p path -l
        hash -p path -r

This adds name, using path, but ignores the other option:
        hash -p path -l name
        hash -p path -d name

Using -t ignores -d:
        hash ls; hash -td ls

And -d ignores -l:
        hash ls; hash -ld ls


Conclusion
I would say that:
- Combining options should error;
- Except for an added -r, which first clears;
- 'hash -l x' shouldn't add, but print what 'hash -lt x' currently prints;
- 'hash -d x' always exits 0, quietly.

Let me know if any of this stuff is wanted, I think I can implement this.

-- 
Regards, Mike Jonkmans

Attachment: bash-hash.patch
Description: Text Data


reply via email to

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