UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Googling for the "which" program is not exactly easy, as the ubiquity of the program name defeats search. sudo apt-get install which doesn't work out of the gate, so I was wondering if someone knew which repository which is found in (confusing?), or if I have to download it and compile from the source.
Googling for the "which" program is not exactly easy, as the ubiquity of the program name defeats search.
In Slackware it is a package called "which" too:
Quote:
GNU 'which' takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash(1). 'Which' is a built-in function in many shells.
The GNU version of which was written by Carlo Wood.
(from the description of the package)
You can find the source on ftp.gnu.org/gnu/which. The latest version is 2.21, which is already 5 years old.
But as it already tells you, in some shells (not bash, as far as I know) it is a built-in, so not an external program. In tchs it IS:
Quote:
which command (+)
Displays the command that will be executed by the shell after substitutions, path searching, etc. The builtin command is just like which(1), but it correctly reports tcsh aliases and builtins and is 10 to 100 times faster.
Now I feel dumb. When I ran sudo apt-cache policy which, it said it wasn't installed. I just tried it: which ping, and the result was the as-expected /bin/ping. Thank you!
Now I feel dumb. When I ran sudo apt-cache policy which, it said it wasn't installed. I just tried it: which ping, and the result was the as-expected /bin/ping. Thank you!
Don't! I just did the same thing - I guess it got folded into BASH at some point.
which on Debian (excluding the version currently in sid) and Ubuntu (excluding not yet released Jammy) is a Debian-specific shell script provided by package debianutils. It was recently deprecated, and now is managed through Debian Alternatives System, so it could be GNU which, or FreeBSD which, or still the old Debian which.
Possible alternatives are listed in the comments to the bug report linked above:
type in any POSIX-compatible shell
command -v in any POSIX-compatible shell
whereis from util-linux
the which builtin in tcsh, zsh
the whence builtin in ksh and its clones
the which() function in /var/lib/dpkg/info/keyboard-configuration.postinst
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.