Portál AbcLinuxu, 1. května 2025 14:14

Dotaz: which a standardy

6.12.2017 12:46 Jirka
which a standardy
Přečteno: 2655×
Odpovědět | Admin
Po x letech programování v shellu jsem ke svému překvapení zjistil, že tolik oblíbený příkaz "which" vůbec není součástí POSIX ani SUS, a dokonce jej nezmiňuje ani LSB, přestože je přítomen téměř na každém unix-like systému.

Tuší někdo, jestli je součástí nějakého obecnějšího standardu, nebo je to jenom taková nepsaná historická tradice, kterou si každý OS řeší samostatně?
Nástroje: Začni sledovat (0) ?Zašle upozornění na váš email při vložení nového komentáře.

Odpovědi

6.12.2017 14:56 NN
Rozbalit Rozbalit vše Re: which a standardy
Odpovědět | | Sbalit | Link | Blokovat | Admin
V Debianu je soucasti baliku debianutils, ktery spravuje Clint Adams. Muzes se ho zeptat.
vencour avatar 6.12.2017 16:26 vencour | skóre: 56 | blog: Tady je Vencourovo | Praha+západní Čechy
Rozbalit Rozbalit vše Re: which a standardy
Odpovědět | | Sbalit | Link | Blokovat | Admin
V gentoo je to následovně ...
$ equery b which
 * Searching for which ... 
sys-apps/which-2.21 (/usr/bin/which)


$ eix sys-apps/which
[I] sys-apps/which
     Available versions:  2.21
     Installed versions:  2.21(18:13:34 23.8.2017)
     Homepage:            https://carlowood.github.io/which/
     Description:         Prints out location of specified executables that are in your path
A na onom odkazu se píše ...
$ cat which.lsm 
Begin3
Title: which
Version: 
Entered-date: 09APR99
Description: Which is a utility that prints out the full path of the
	     executables that bash(1) would execute when the passed
	     program names would have been entered on the shell prompt.
	     It does this by using the exact same algorithm as bash.
	     Tildes and a dot in the PATH are now expanded to the
	     full path by default.  Options allow to rather print
	     "~/*" or "./*" and/or to print all exectuables that
	     match any directory in PATH.
Keywords: which utility directory path executable bash
Author: carlo at gnu.org (Carlo Wood)
Maintained-by: carlo at alinoe.com (Carlo Wood)
Primary-site: http://www.xs4all.nl/~carlo17/which/
Original-site:
Alternate-site: ftp.gnu.org /gnu/which
Platforms: linux netbsd freebsd bsdi osf1, probably all UNIX.
Copying-policy: GPL
End
Ty nejhlubší objevy nečekají nutně za příští hvězdou. Jsou uvnitř nás utkány do vláken, která nás spojují, nás všechny.
8.12.2017 13:10 marbu | skóre: 31 | blog: hromada | Brno
Rozbalit Rozbalit vše Re: which a standardy
Na Fedoře se taky používá verze, kterou v upstreamu spravuje Carlo Wood v rámci projektu GNU:
$ rpm -qi which
Name        : which
Version     : 2.21
Release     : 2.fc26
Architecture: x86_64
Install Date: Mon 17 Jul 2017 10:47:07 AM CEST
Group       : Applications/System
Size        : 77261
License     : GPLv3
Signature   : RSA/SHA256, Mon 13 Feb 2017 12:39:48 PM CET, Key ID 812a6b4b64dab85d
Source RPM  : which-2.21-2.fc26.src.rpm
Build Date  : Sun 12 Feb 2017 05:05:13 AM CET
Build Host  : buildhw-10.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://savannah.gnu.org/projects/which/
Summary     : Displays where a particular program in your path is located
Description :
The which command shows the full pathname of a specified program, if
the specified program is in your PATH.
V README souboru je pak krátká zmínka o historii:
History
=======

The main difference with version 1.0 by Paul Vixie is that this
version will not return directory names as being executables
and that by default it will expand a leading "./" and "~/" to
its full path on output.

The -all option has been added in example of a version of which
on Ultrix.  They use `-a' as option.

The --read-alias idea has been copied from a version of which by
Maarten Litmaath called `which-v6', he was using `-i' as option
which stands for `interactive'.
Wikipedia pak pro which (Unix) žádný standard neuvádí.

Ale vtipné je, že na té wikipedii píšou, že existuje posixový standard pro příkaz command, který pracuje podobně:
$ command -v dnf
/usr/bin/dnf
V textu toho standardu pak píšou:
The command -v and -V options were added to satisfy requirements from users that are currently accomplished by three different historical utilities: type in the System V shell, whence in the KornShell, and which in the C shell. Since there is no historical agreement on how and what to accomplish here, the POSIX command utility was enhanced and the historical utilities were left unmodified. The C shell which merely conducts a path search. The KornShell whence is more elaborate-in addition to the categories required by POSIX, it also reports on tracked aliases, exported aliases, and undefined functions.
Takže je to takonec tak, že `which` není v žádném standardu protože na tom nebyla shoda, a standardizovaný je místo toho ten `command`.
There is no point in being so cool in a cold world.
8.12.2017 13:13 marbu | skóre: 31 | blog: hromada | Brno
Rozbalit Rozbalit vše Re: which a standardy
Na unix.stackexchange.com je pak další historický kontext Why not use “which”? What to use then?.
There is no point in being so cool in a cold world.
8.12.2017 13:40 Aleš Kapica | skóre: 52 | blog: kenyho_stesky | Ostrava
Rozbalit Rozbalit vše Re: which a standardy
Díky za ten link!
8.12.2017 17:26 Jirka
Rozbalit Rozbalit vše Re: which a standardy
Díky za odpovědi. Já léta žiju v domnění, že používat which je kdovíjak univerzální a přenositelné; aspoň jsem se ještě nesetkal se systémem kde by nebyl, ale zřejmě tedy vůbec v žádném standardu není:)

Jinak ještě existuje taky "type", ale to už je bohužel zase jenom v XSI, takže čistě posixový je asi jedině command.

Založit nové vláknoNahoru

Tiskni Sdílej: Linkuj Jaggni to Vybrali.sme.sk Google Del.icio.us Facebook

ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.