help-bash
[Top][All Lists]
Advanced

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

Re: type -aP: intentional behaviour or a bug?


From: Chet Ramey
Subject: Re: type -aP: intentional behaviour or a bug?
Date: Fri, 16 Dec 2022 14:44:32 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

On 12/15/22 7:18 PM, Adam Vodopjan wrote:
Hey guys!

I need to expand a command to all its locations under $PATH. For example,
on my system /bin is a symlink to /usr/bin so for 'ls' there should be
both /usr/bin/ls and /bin/ls listed.

OK.


For the purpose I wanted to use either 'type -ap' or 'type -aP'. I know
there is a difference in 'type -p' vs 'type -P':

`type -aP' is the more appropriate choice, since it forces the $PATH search.


But I was sure '-ap' should be the same as '-aP'. Somehow I've found out
this:

Yes, `type -aP' looks in the hash table. That's really the only difference.
It's been that way since I added it in 2001. I forget why, but it was
probably something like why force the $PATH search when it's not going to
be used when you use the name as a command. That's a long time ago, though.

If you want to force the $PATH search, remove the name from the hash
table before doing it (hash -d ls).

   /* If the user isn't doing "-a", then we might care about
      whether the file is present in our hash table. */
   if (all == 0 || (dflags & CDESC_FORCE_PATH))

So with CDESC_FORCE_PATH bit set (-P flag) it completely ignores -a flag.

No, only if it's present in the hash table.

--
``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]