Zsh `which rvm` 或 `which gem` 返回函数内容而不是路径 [英] Zsh `which rvm` or `which gem` returns the function contents instead of the path
问题描述
我以前在我的其他机器上从来没有遇到过这个问题,但由于某种原因,每当我输入时在 ZSH 中
I've never had this problem before with my other machines but for some reason in ZSH whenever I type
which gem
或
which rvm
我得到了函数内容:
gem () {
local result
command gem "$@"
result="$?"
hash -r
return $result
}
而不是它的路径.对于我的生活,我无法弄清楚为什么会发生这种情况.
instead of it's path. For the life of me I can not figure out why this is happening.
如果我切换到 bash,我就不会有这些问题.
If I switch over to bash I do not have these problems.
推荐答案
这是 zsh 的正常行为.内置的 which
等价于 whence -c
,它显示了函数的定义.使用 whence
,如果您不想要的话,可以使用不包含 -f
或 -c
的选项组合.例如whence -w gem
将显示gem: function
.如果您只想搜索外部可执行文件(而不是别名、内置函数、保留字或函数),请使用 whence -v
.
This is normal behavior for zsh. The which
built-in is equivalent to whence -c
, which shows the definitions of functions. Use whence
, possibly with a combination of options that does not include -f
or -c
, if you don't want this. For example whence -w gem
will display gem: function
. If you only want to search for external executables (and not aliases, built-ins, reserved words or functions), use whence -v
.
这篇关于Zsh `which rvm` 或 `which gem` 返回函数内容而不是路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!