On Sat, Jan 20, 2018 at 5:30 AM, Patrick O'Callaghan
<pocallag...@gmail.com> wrote:
> On Sat, 2018-01-20 at 04:34 -0500, Tom H wrote:
>> On Sat, Jan 20, 2018 at 2:10 AM, Cameron Simpson <c...@cskk.id.au> wrote:
>>>
>>> Also: "which rm" should show what executable is being used, and the
>>> bash "which" IIRC also shows if an alias or function is involved (I'm
>>> a zsh person myself).
>>
>> There's no "which" builtin in bash. IIRC, only tcsh and zsh have one.
>
> Personally I just use 'type' rather than 'which'.

"type" is the shortest and, like the others, it works for most commands.

"command", "type", "which" as well as "where" in tcsh and zsh,
"whence" in *ksh, "whereis" from util-linux all have their
peculiarities.


"command" and "type" list the first hit in the order of command expansion:

aliases > functions > builtins > first hit in $PATH


"type -a" lists all hits in the order of command expansion.


"which" only checks $PATH and lists the first hit.

"which -a" only checks $PATH and lists all hits in the order of $PATH expansion.

(GNU "which", used on Fedora, has an option for aliases.)


So you end up with edge cases. The output below is from my Mac because
I'm out and not ssh'd into a Linux system:

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.

$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin



$ sudo ln -s /bin/echo /usr/local/bin/echo
$ alias echo='/bin/echo -n'



$ which echo
/usr/local/bin/echo

$ which -a echo
/usr/local/bin/echo
/bin/echo

$ type echo
echo is aliased to `/bin/echo -n'

$ type -a echo
echo is aliased to `/bin/echo -n'
echo is a shell builtin
echo is /usr/local/bin/echo
echo is /bin/echo

$ command -v echo
alias echo='/bin/echo -n'

$ command -V echo
echo is aliased to `/bin/echo -n'



$ unalias echo



$ which echo
/usr/local/bin/echo

$ which -a echo
/usr/local/bin/echo
/bin/echo

$ type echo
echo is a shell builtin

$ type -a echo
echo is a shell builtin
echo is /usr/local/bin/echo
echo is /bin/echo

$ command -v echo
echo

$ command -V echo
echo is a shell builtin



$ sudo rm /usr/local/bin/echo



$ which echo
/bin/echo

$ which -a echo
/bin/echo

$ type echo
echo is a shell builtin

$ type -a echo
echo is a shell builtin
echo is /bin/echo

$ command -v echo
echo

$ command -V echo
echo is a shell builtin

$
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org

Reply via email to