[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: type -aP: intentional behaviour or a bug?
From: |
Adam Vodopjan |
Subject: |
Re: type -aP: intentional behaviour or a bug? |
Date: |
Tue, 20 Dec 2022 03:17:44 +0200 |
On 19/12/2022 18:17, Chet Ramey wrote:
> On 12/16/22 7:33 PM, Adam Vodopjan wrote:
>
>>
>> Bash man page: 'If a command is hashed, -p and -P print the hashed value',
>> but it says later: 'The table of hashed commands is not consulted when
>> using -a'.
>
> Right, unless -P is supplied to force it.
>
>> It looks like a 20 yo bug, or a problem with docs. '-a' states for
>> 'everything', not for 'everything, if only it is not hashed yet in case of
>> -P. But with -p it is everything indeed'.
>
> Then let's see if we can rationalize the behavior. They have to differ,
> otherwise there's no reason to have both.
As per type.def, -p vs -P is CDESC_FORCE_PATH flag. With it enabled:
1) alias, keyword, function and builtin blocks are bypassed
2) hash search is still performed with -a
If we drop the latter, so both -pa and -Pa skip hash, there is still
the former. Did you take into account -p is affected by existing
aliases, keywords, functions and builtins?
In the following:
group_A = alias, keyword, function, builtin
group_B = absolute path, hash entry, $PATH
-p outcomes:
1) exit code=0, nothing printed = found in group_A, group_B is not
even tried
2) exit code=0, something printed = not found in group_A, but found in
group_B
3) exit code=1, nothing printed = not found in both groups
-P is not aware of group_A. There are two outcomes:
1) exit code=0, something printed = found in group_B
2) exit code=1, nothing printed = not found in group_B
There are differences with -a as well.
-pa outcomes:
1) exit code=0, nothing printed = found in group_A, not found in
group_B
2) exit code=0, something printed = found in group_B, group_A doesnt
affect the result
3) exit code=1, nothing printed = not found in both groups
-Pa outcomes:
1) exit code=0, something printed = found in group_B
2) exit code=1, nothing printed = not found in group_B
I think the only thing to change is dropping the CDESC_FORCE_PATH
condition from the hash block. So that it is never entered with -a.
>
> How's this: -P skips everything but hashed pathnames and path searches, and
> unless -a is supplied, stops at the first pathname that will be executed
> for a given NAME. -p does path searches, and, unless -a is supplied, shows
> you what would be executed (and hashed) for a given NAME as long as nothing
> else would take precedence over it.
>
> Then we can change the behavior of `type -ap' and `type -aP', which are
> sort of orthogonal to the rest of `type'. We don't really need to change
> `type -ap', but we can add a PATH search to a successful hash table
> lookup for `type -aP'.
>