6

I want to use the which command to see which executable is actually being invoked, but the defensive noglob aliases keep getting in the way.

Is there a shortcut that I can use to find which executable is invoked when the command is aliased ?

I am using the zsh shell.

tread
  • 386
Ivar
  • 113

2 Answers2

11

You can use which -a COMMAND (or where COMMAND or whence -ca COMMAND) to find all occurences of COMMAND in the command path.

For example:

% alias ls='noglob ls'
% ls () /bin/ls
% which ls
ls: aliased to noglob ls
% which -a ls
ls: aliased to noglob ls
ls () {
        /bin/ls
}
/bin/ls

As aliases are replaced in the command line before anything is executed, the second command in the list is the one you are looking for (assuming of course that the first line is somehow aliased to the same name)

Adaephon
  • 6,094
2

Use which -p e.g.:

✗ which ls
ls: aliased to ls --color=tty
✗ which -p ls
/bin/ls

From https://linux.die.net/man/1/zshbuiltins:

(whence) -p

Do a path search for name even if it is an alias, reserved word, shell function or builtin.