23

I read `which`, but all but I cannot really get the difference. I am running zsh 5.4.2 on 64-bit debian-buster. Both which and whence are shell-builtins .

Can people point out where whence would be more appropriate than which and vice-versa ?

/home/shirish> zsh --version
zsh 5.4.2 (x86_64-debian-linux-gnu)

/home/shirish> type -a which
which is a shell builtin
which is /usr/bin/which
which is /bin/which

/home/shirish> type -a whence
whence is a shell builtin
0

2 Answers 2

34

which was a csh command (well a csh script that read your ~/.cshrc), whence was the Korn shell's answer to csh's which, type the Bourne shell one, command -v/V the POSIX one...

zsh implements ksh's whence with a few extensions, but also provides a which alias for the csh junkies and type/command -v/V for POSIX compliance which are just the same command but with different default behaviour.

  • which is whence -c (c for csh)
  • type is whence -v (more verbose whence)
  • where is whence -ca
  • POSIX command -v is like whence
  • POSIX command -V is like whence -v

You'll find some more information (though in a bit of a messy way, sorry) at Why not use "which"? What to use then?

2
  • @dr_, I've reverted your edit. There is no whereis builtin in zsh. There is a whereis command on BSDs or in util-linux, but that has nothing to do with whence -ca. See info zsh where for the documentation about zsh's where. Commented Oct 13, 2021 at 15:27
  • Ok, sorry for the edit. I did not realize your third paragraph referred exclusively to zsh. I was referring to Bash.
    – dr_
    Commented Oct 14, 2021 at 11:00
1

whence [ -vcfpam ] name ... For each name, indicate how it would be interpreted if used as a command name. The -v flag produces a more verbose report. The -c flag prints the results in a csh-like format and takes precedence over -v. The -f flag causes the contents of a shell function to be displayed, which would otherwise not happen unless the -c flag were used. The -p flag does a path search for name even if it is an alias, reserved word, shell function or builtin. The -a flag does a search for all occurrences of name throughout the command path. With the -m flag, the arguments are taken as patterns (which should be quoted), and the information is displayed for each command matching one of these patterns.

which [ -pam ] name ... Same as whence -c.

You should check the zsh manual

Not the answer you're looking for? Browse other questions tagged .