Many years ago, I did “which cd” and it told me “cd: shell built-in command.”
Recently, I tried it and got:
/usr/bin/which: no cd in ([obscenely long path I will not reproduce here])
I investigated and found that someone had aliased which:
> which which
which alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde
/usr/bin/which
Once I unaliased which, “which cd” worked again properly. My questions:
-
How can I make “which” work with both aliases AND shell built-ins?
-
I couldn’t find where the “which” alias is created (it’s not in
/etc/cshrc, ~/.cshrc, etc for example). Where does this happen so I
can defeat/edit it permanently?
EDIT: Thanks to everyone who helped. I think I’ve figured this out:
- “which” is a tcsh built-in, not the same thing as “/usr/bin/which”:
> unalias which; which which which: shell built-in command.
- “unalias which” pretty much does the trick. It works with builtins
(as above) and aliases (and correctly recognizes the backslash as an
alias escape), as below:
> alias foo bar; which foo foo: aliased to bar > which \foo foo: Command not found.
- The alias appears to come from /etc/profile.d/which2.csh on my
system, which is odd because I thought profile.d was only for
sh/bash, not csh/tcsh
On Redhat systems, it looks like its defined in /etc/profile.d/which.sh
To try the unaliased command I did:
so I’m not sure where your builtin output is coming from.