[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What can affect whether a comamnd is found in PATH?
From: |
Jeffrey Walton |
Subject: |
Re: What can affect whether a comamnd is found in PATH? |
Date: |
Thu, 24 Jun 2021 09:19:03 -0400 |
On Wed, Jun 23, 2021 at 2:33 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> $ type -P cmd
>
> I am trying to find a command using the above command. But it finds nothing.
>
> Then I call the command with its abspath.
>
> $ /abs/path/cmd
>
> Then I can find the command. I also run `hash -r` before. But it didn't help.
>
> $ type -P cmd
> /abs/path/cmd
>
> `type` is the following builtin.
>
> $ type type
> type is a shell builtin
>
> This looks weird. Does anybody know how to debug this issue?
>
> Can I exclude the possibility that this is caused by a bug in this
> version of bash?
Use 'command -v' to locate a command, not 'type' or 'which' or other
random things you find on Stack Overflow.
'command -v' handles PATH and other things that affect locating a
program, like an alias.
The 'command' command is Posix so it works everywhere.
$ command -v awk
/usr/bin/awk
$ command -v grep
alias grep='grep --color=auto'
Jeff