TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Debian's Which Hunt

366 点作者 ajdecon超过 3 年前

38 条评论

kelnos超过 3 年前
&gt; * The POSIX-blessed way of finding an executable program is command -v, which is consequently built into most shells. Given the standard alternative, Adams said, &quot;surely no one competent would choose to have a package depend on `which` when a standard POSIX utility can do a better job&quot;.*<p>This feels a little tone-deaf to me. I&#x27;ve been using the *nix command-line and writing (and reading) shell scripts for 20+ years, and I&#x27;d never heard of &quot;command -v&quot; until now. Now that I know about it, I&#x27;ll probably start trying to retrain my muscle memory to use it (though it requires 2x the number of keystrokes).<p>Despite its lack of true standardization, &quot;which&quot; (along with &quot;type -p&quot;) has been the de-facto &quot;standard&quot; I&#x27;ve seen in shell scripts for figuring out if a command exists. It was a surprise to me to learn that &quot;which&quot; isn&#x27;t a part of POSIX, even.
评论 #29034501 未加载
评论 #29033320 未加载
评论 #29035528 未加载
评论 #29034940 未加载
评论 #29036008 未加载
评论 #29082102 未加载
kbenson超过 3 年前
Regardless of whether &#x27;command -v&#x27; is a better alternative, &#x27;which&#x27; is ensconced as standard practice in many shell scripts, and I would go so far as to say I think the majority of them that actually have to choose between the two use &#x27;which&#x27;.<p>Given that, having it print out a deprecation warning without considering what that means to all the people that use it is irresponsible. I help manage a few hundred servers. We send root email to a list and actually review it all every day. We make sure to sanitize anything run from cron so that we only get email output on error (STDERR). Given that some of those cron jobs run quite often, this would have been <i>thousands</i> of emails to sift through if we used Debian.<p>There were many possible solutions, as the maintainer notes. Unfortunately in trying to remove themself from the decision, they forced a non-solution on everyone that is disruptive. I can&#x27;t think of any way this is a good choice for this particular set of facts (I can see a deprecation warning being warranted for some other things, but this case has little to do factually with those theoretical situations).
评论 #29035112 未加载
评论 #29032075 未加载
评论 #29049680 未加载
评论 #29035382 未加载
pornel超过 3 年前
I&#x27;m a descriptivist when it comes to standards. When everyone uses `which`, POSIX should add it. &quot;but it&#x27;s non-standard!&quot; can be fixed by making it a standard.
评论 #29028752 未加载
评论 #29032758 未加载
评论 #29029741 未加载
评论 #29029875 未加载
评论 #29035010 未加载
评论 #29030906 未加载
overgard超过 3 年前
When I read stuff like this I can&#x27;t help but wonder how anything ever even gets done on this project. The amazing thing is &#x27;which&#x27; was working perfectly fine for everyone. Just leave it alone? The amount of time they wasted on debating this is staggering compared to just not changing it.
评论 #29030553 未加载
评论 #29033160 未加载
评论 #29031852 未加载
评论 #29033087 未加载
评论 #29031324 未加载
emptyparadise超过 3 年前
Seems like this is a case of Debian governance working as designed. I&#x27;m surprised that &#x27;which&#x27; isn&#x27;t POSIX though.
评论 #29029551 未加载
评论 #29027691 未加载
评论 #29033112 未加载
OliverJones超过 3 年前
By this logic, we&#x27;d also rename awk to something more &quot;meaninful&quot; because the names of Aho, Kernighan, and Weinberger are just historical artifacts. They are indeed, but we&#x27;re talking about a real-world &quot;we all talk UNIX&quot; language here that&#x27;s been around for a long time -- perilously close to 2.14 billion seconds in fact. Lots of people and programs speak, read, and write this UNIX language. It&#x27;s creeping up on natural human language status. This &quot;which&#x27; is a vocabulary word of that language.<p>Heavily used languages evolve. And you know what? They never evolve healthily when they ban the use of &quot;obsolete&quot; vocabulary. Languages embody history. Even PowerShell!<p>This language won&#x27;t benefit from an Académie Française - style iron-fisted rule.
评论 #29032588 未加载
jagger27超过 3 年前
Here&#x27;s how zsh 5.8 behaves on macOS:<p><pre><code> $ which {which,type,command,vi} which: shell built-in command type: shell built-in command command: shell built-in command &#x2F;usr&#x2F;bin&#x2F;vi $ type {which,type,command,vi} which is a shell builtin type is a shell builtin command is a shell builtin vi is &#x2F;usr&#x2F;bin&#x2F;vi $ command -v {which,type,command,vi} which type command &#x2F;usr&#x2F;bin&#x2F;vi </code></pre> Which is quite different from how bash 5.1 behaves:<p><pre><code> bash-5.1$ which {which,type,command,vi} &#x2F;usr&#x2F;bin&#x2F;which &#x2F;usr&#x2F;bin&#x2F;type &#x2F;usr&#x2F;bin&#x2F;command &#x2F;usr&#x2F;bin&#x2F;vi bash-5.1$ type {which,type,command,vi} which is hashed (&#x2F;usr&#x2F;bin&#x2F;which) type is a shell builtin command is a shell builtin vi is &#x2F;usr&#x2F;bin&#x2F;vi bash-5.1$ command -v {which,type,command,vi} &#x2F;usr&#x2F;bin&#x2F;which type command &#x2F;usr&#x2F;bin&#x2F;vi </code></pre> I wouldn&#x27;t want to be the one responsible for making this change, that&#x27;s for sure.<p>command -v does seem like the most reasonable choice in both circumstances, though.<p>&#x2F;usr&#x2F;bin&#x2F;type and &#x2F;usr&#x2F;bin&#x2F;command are indeed just the same shell scripts.<p><pre><code> file &#x2F;usr&#x2F;bin&#x2F;{which,type,command} &#x2F;usr&#x2F;bin&#x2F;which: Mach-O universal binary [...] &#x2F;usr&#x2F;bin&#x2F;type: POSIX shell script text executable, ASCII text &#x2F;usr&#x2F;bin&#x2F;command: POSIX shell script text executable, ASCII text cat &#x2F;usr&#x2F;bin&#x2F;command #!&#x2F;bin&#x2F;sh # $FreeBSD: src&#x2F;usr.bin&#x2F;alias&#x2F;generic.sh,v 1.2 2005&#x2F;10&#x2F;24 22:32:19 cperciva Exp $ # This file is in the public domain. builtin `echo ${0##*&#x2F;} | tr \[:upper:] \[:lower:]` ${1+&quot;$@&quot;}</code></pre>
评论 #29029181 未加载
评论 #29031336 未加载
评论 #29034051 未加载
评论 #29031389 未加载
评论 #29029662 未加载
stonogo超过 3 年前
I find it interesting that Debian even cares whether &#x27;which&#x27; is POSIX or not, given that they don&#x27;t ship a lot of POSIX commands (e.g. &#x27;ed&#x27; and &#x27;bc&#x27;) by default. It seems to me much of the value in such a standard is you can either rely on it or not; deliberately omitting some of the specified utilities, then using other utilities as arguments in a systems architeecture discussion seems like a self-contradiction. Unfortunately the Debian wiki entry on POSIX merely defines it and doesn&#x27;t enlighten us as to policy decisions.
评论 #29028233 未加载
soraminazuki超过 3 年前
Searching the Nix package repository can give you a good idea of how prevalent some software are used as a dependency because Nix packages requires all dependencies to be explicitly specified by design. Now, a quick search for &quot;which&quot; yields 2.5k hits [1]. Although a non-negligible portion of hits are just common uses of the word &quot;which&quot; in code comments, the other large portion of the hits are indeed dependencies on the &quot;which&quot; package. Although the use of the &quot;which&quot; command might potentially be fragile when considering cross-platform use, it seems like a really bad idea to deprecate it from a pragmatic point of view.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;NixOS&#x2F;nixpkgs&#x2F;search?l=Nix&amp;q=which" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;NixOS&#x2F;nixpkgs&#x2F;search?l=Nix&amp;q=which</a>
AceJohnny2超过 3 年前
I gotta believe Mr Corbet&#x27;s impetus for writing this story was for the season-appropriate pun. But as always, he still produced an insightful story on important Linux infrastructure.
throwaway09223超过 3 年前
There&#x27;s a problem with &quot;command -v,&quot; in that it&#x27;s not actually a command. It&#x27;s a Bourne shell builtin.<p>You can&#x27;t use `command -v` in csh or other shells, only in Bourne style shells (bash, zsh, etc).<p>&#x2F;usr&#x2F;bin&#x2F;which is a standalone binary. It can be invoked without a shell at all.<p>Many comments discussing `command` being part of POSIX are I think missing that `command` is only part of POSIX insofar as the Bourne shell is defined by POSIX. It is part of a POSIX `&#x2F;bin&#x2F;sh` and is not its own thing.<p>Keeping &#x2F;usr&#x2F;bin&#x2F;which is the correct decision and it should probably be added to POSIX.
评论 #29033974 未加载
dilawar超过 3 年前
&#x27;command -v&#x27; is POSIX!! I have always avoided it in favor of which because its output doesn&#x27;t feel machine friendly.
评论 #29027486 未加载
评论 #29029678 未加载
评论 #29028817 未加载
评论 #29028033 未加载
评论 #29027746 未加载
评论 #29027678 未加载
评论 #29032472 未加载
评论 #29027481 未加载
nonameiguess超过 3 年前
&gt; The POSIX-blessed way of finding an executable program is command -v, which is consequently built into most shells. Given the standard alternative, Adams said, &quot;surely no one competent would choose to have a package depend on `which` when a standard POSIX utility can do a better job&quot;.<p>While I can understand having this attitude, a whole lot of package build scripts, not just in Debian, but in the upstreams, rely upon which existing and printing out the path of an executable without a deprecation warning. I would expect a Debian maintainer to realize that. Debian does patch the heck out of upstream packages, but they don&#x27;t provide everything, and all Debian users are not going to want to go to equal effort to patch all of the build files for packages Debian doesn&#x27;t provide.
评论 #29028085 未加载
评论 #29029535 未加载
评论 #29028493 未加载
unethical_ban超过 3 年前
&gt;&quot;surely no one competent would choose to have a package depend on `which` when a standard POSIX utility can do a better job&quot;<p>I&#x27;m immediately turned off by this person. They don&#x27;t say exactly who or when the command was altered to put the warning in place, but it sounds like one inept, opinionated person decided to flip a switch without caring about any other practical reasons that conflict with his puritan take.
评论 #29030353 未加载
pxc超过 3 年前
Huh. Apparently `command` is a shell builtin for POSIX shells, not a standalone program. You might still want `which` if you&#x27;re running in a non-POSIX shell that doesn&#x27;t implement `command`.<p>Seems fine to deprecate its usage inside bash scripts or scripts that you know are pegged to an interpreter that implements `command`, though.
评论 #29028908 未加载
mikl超过 3 年前
`which` is an extremely commonly used command, has an intuitive name, is a very small program.<p>Removing it from the standard distribution would be a huge annoyance to everyone who uses it. One more package you have to remember to install on every system to be productive.
评论 #29049871 未加载
donatj超过 3 年前
The base Debian docker images don&#x27;t come with `ps` either, which caused me a world of hurt earlier this year.
asicsp超过 3 年前
Reminds me of this famous Q&amp;A &quot;Why not use &quot;which&quot;? What to use then?&quot; - <a href="https:&#x2F;&#x2F;unix.stackexchange.com&#x2F;questions&#x2F;85249&#x2F;why-not-use-which-what-to-use-then" rel="nofollow">https:&#x2F;&#x2F;unix.stackexchange.com&#x2F;questions&#x2F;85249&#x2F;why-not-use-w...</a>
_kst_超过 3 年前
Without commenting on what Debian should do about this, I&#x27;ve pretty much given up using `which` myself.<p>Since `which` is an external command (it&#x27;s built into some shells, but not bash), it doesn&#x27;t know about aliases, shell functions, or builtin shell commands.<p>I&#x27;ve found that bash&#x27;s built-in `type` command (with its various options) does whatever `which` does, and often does it better.<p>I also use `command -v foo &gt;&#x2F;dev&#x2F;null` to detect whether the command `foo` exists -- for example:<p><pre><code> if command -v less &gt;&#x2F;dev&#x2F;null ; then export PAGER=less fi </code></pre> I suppose I could also use `type` for the same purpose.<p>It would be nice if `type` and&#x2F;or `command` had an option to check whether a command exists without printing anything, but having to add `&gt;&#x2F;dev&#x2F;null` is only a minor annoyance.
mise_en_place超过 3 年前
I actually disagree that they shouldn&#x27;t allow alternatives for `which`. IMO, just provide all of them and let the user decide. I should be able to choose from GNU which, BSD which, busybox which, or an alias to `command -v`. Default just keep it as GNU which.
评论 #29028919 未加载
darkwater超过 3 年前
My memory might be tricking me but I learnt about &#x27;which&#x27; on a late &#x27;80s HP9000 running HP-UX, using bourne shell and it&#x27;s output was the same as GNU which. But I might be swapping memories with early Linux.
dwheeler超过 3 年前
A great thing about the POSIX standard is that it&#x27;s publicly available. See: <a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799.2018edition&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799.2018edition...</a><p>You can see more about &quot;command&quot; here: <a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;command.html" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;c...</a>
sigzero超过 3 年前
The only think I don&#x27;t like about command -v is that it will output the alias if one is set. That is 100% of the time what I do not want.
0xbadcafebee超过 3 年前
Distributions that ship their own distro-specific custom version of an already popular tool need to have their heads examined.
binkHN超过 3 年前
I can appreciate this. I&#x27;ve seen similar things come up in the OpenBSD community. A lot of thought is given, but often times a decision is made fairly judiciously by the benevolent dictator, Theo.
Pxtl超过 3 年前
Going from being the recommended way to do something into being deprecated in under 2 years is such hard deprecation whiplash they&#x27;re going to make Google jealous.
dec0dedab0de超过 3 年前
I&#x27;m still mad at whoever removed screen from redhat.
a0-prw超过 3 年前
I&#x27;ve used Debian since (I think) from late 00s and Linux from 98. Didn&#x27;t even know what Which does. Maybe I forgot ;)
egberts1超过 3 年前
also - ‘which’, being too Debian-specific, will not return the filespec if its file permission is too restrictive.<p>- ‘command -v’, also will not display binary if its file permission is too restrictive.<p>- ‘whereis -b’ works just fine as long as &#x2F;usr&#x2F;sbin has world RX file mode or other lesser matching filemods.<p>Still stuck on ‘whereis’
fractalb超过 3 年前
I don&#x27;t really understand what the need is to kill off `which` command. Is it a maintenance burden?
评论 #29035595 未加载
billpg超过 3 年前
I remember writing scripts with $(which something) in the past. I cannot remember why I needed that.
gorgoiler超过 3 年前
SunOS’s which always returned 0, no matter what. Good times that, thanks for the memory, ahem.
shmerl超过 3 年前
Never heard of command, thanks for pointing it out!<p>Try this:<p><pre><code> command -V command command -V which</code></pre>
dekhn超过 3 年前
I use &#x27;type&#x27; because many commands end up being aliases or bash functions :(
cryptonector超过 3 年前
Removing `which(1)` -- them&#x27;s fightin&#x27; words right there.
luord超过 3 年前
Duly noted: get used to `command -v`<p>Better to follow standards anyway.
machinesbuddy超过 3 年前
TIL about `command -V` (the verbose flag)!
vidanay超过 3 年前
Wow, talk about a tempest in a tea kettle. Bikeshedding like this is why Linux will never achieve any significant market share for average consumers. (Because all that mental effort could have been spent on solving some real problem instead of philosophical conformity.)
评论 #29027276 未加载
评论 #29027262 未加载
评论 #29027225 未加载
评论 #29027646 未加载
评论 #29027613 未加载
评论 #29027506 未加载
评论 #29027199 未加载
评论 #29027239 未加载
评论 #29027428 未加载
评论 #29028111 未加载