LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   Installing "which" on Ubuntu 18.04.4 (https://www.linuxquestions.org/questions/ubuntu-63/installing-which-on-ubuntu-18-04-4-a-4175673310/)

Bill_Blessing 04-15-2020 02:45 PM

Installing "which" on Ubuntu 18.04.4
 
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.

which is needed for me to get Buildroot set up.

ehartman 04-15-2020 03:16 PM

Quote:

Originally Posted by Bill_Blessing (Post 6112095)
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.
(from the man page for tcsh)

Bill_Blessing 04-15-2020 03:36 PM

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!

cement_head 02-05-2022 06:54 AM

Quote:

Originally Posted by Bill_Blessing (Post 6112112)
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.

shruggy 02-05-2022 08:27 AM

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
  • etc.


All times are GMT -5. The time now is 02:20 AM.