bug-bash
[Top][All Lists]
Advanced

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

Re: hash -d 0/1 and other hash stuff


From: Chet Ramey
Subject: Re: hash -d 0/1 and other hash stuff
Date: Mon, 11 Sep 2023 15:25:01 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0

On 9/6/23 10:55 AM, Mike Jonkmans wrote:
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'.

It's whether the hash table is empty. `hash -d' shortcuts if the hash
table is empty, but I agree that it should not.


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.

The parallel is with `unalias', which does the same thing if the alias
being removed isn't in the alias table.


2) 'hash x' and 'hash -l x' seem to do the same

Yes. The `-l' option is an output format modifier; it takes -t to print
the hashed commands.


'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).

The `-t' option says to list the contents of the hash table; the `-l'
option modifies the output format.


3) These option combinations should error/exit 1:

Agreed, except for

        hash -p path -t name

which is valid, if ambiguous. `hash' prioritizes -t over -p in this case.


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

Because it's not listing output, and -l is an output modifier.

        hash -p path -d name

This is, again, ambiguous, and hash prioritizes -p over -d.


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

Ambiguous; hash prioritizes -t over -d.


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

Because -l is an output format modifier.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

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