LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 04-15-2020, 02:45 PM   #1
Bill_Blessing
LQ Newbie
 
Registered: Aug 2007
Location: Cincinnati
Distribution: Opensuse Leap 15.0
Posts: 26

Rep: Reputation: 2
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.
 
Old 04-15-2020, 03:16 PM   #2
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by Bill_Blessing View Post
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)
 
1 members found this post helpful.
Old 04-15-2020, 03:36 PM   #3
Bill_Blessing
LQ Newbie
 
Registered: Aug 2007
Location: Cincinnati
Distribution: Opensuse Leap 15.0
Posts: 26

Original Poster
Rep: Reputation: 2
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!
 
1 members found this post helpful.
Old 02-05-2022, 06:54 AM   #4
cement_head
Member
 
Registered: Mar 2006
Location: Oxford, OH, USA
Distribution: Ubuntu 10.04.1 LTS (Lucid Lynx)
Posts: 37

Rep: Reputation: 15
Quote:
Originally Posted by Bill_Blessing View Post
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.
 
Old 02-05-2022, 08:27 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,673

Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Replace a string @CURRANGE("***","***") to @CURRANGE("xxx","xxx") in a file mavadikarmayur Linux - Newbie 3 03-26-2012 08:32 AM
[SOLVED] [partition] Which ID to use to get "fat16", "fat32", or "vfat"? littlebigman Linux - Software 6 03-12-2012 09:24 AM
"001" and "0012" converted to "01", "12". How? stf92 Programming 7 07-08-2011 06:55 PM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 06:02 PM
New To """"l I N U X"""" chawla_ab LinuxQuestions.org Member Intro 3 01-22-2006 11:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 04:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration