在 shell 的给定实例中,二进制文件的路径确实被缓存。清除此问题的最简单方法是打开一个新的终端窗口。但您也可以使用内置的 hash shell 在现有窗口中清除它(有关详细信息,请阅读 help hash)。
至于为什么 which 与 shell 关于要执行的二进制文件不一致,这是因为 which 是一个位于 /usr/bin/which 的程序并独立于 shell 解析 PATH。如果您想准确查看 shell 所看到的内容,请使用 type 而不是 which (并使用 type -a 查看所有可能的结果给定的命令)。
Within a given instance of the shell, paths for binaries are indeed cached. The simplest way to clear this is to just open a new terminal window. But you can clear it in an existing window too by using the hash shell built-in (read help hash for details).
As for why which disagrees with the shell about the binary to execute, it's because which is a program that lives at /usr/bin/which and parses the PATH independently of the shell. If you want to see exactly what the shell is seeing, use type instead of which (and use type -a to see all possible results for a given command).
发布评论
评论(1)
在 shell 的给定实例中,二进制文件的路径确实被缓存。清除此问题的最简单方法是打开一个新的终端窗口。但您也可以使用内置的
hash
shell 在现有窗口中清除它(有关详细信息,请阅读help hash
)。至于为什么
which
与 shell 关于要执行的二进制文件不一致,这是因为which
是一个位于/usr/bin/which
的程序并独立于 shell 解析PATH
。如果您想准确查看 shell 所看到的内容,请使用type
而不是which
(并使用type -a
查看所有可能的结果给定的命令)。Within a given instance of the shell, paths for binaries are indeed cached. The simplest way to clear this is to just open a new terminal window. But you can clear it in an existing window too by using the
hash
shell built-in (readhelp hash
for details).As for why
which
disagrees with the shell about the binary to execute, it's becausewhich
is a program that lives at/usr/bin/which
and parses thePATH
independently of the shell. If you want to see exactly what the shell is seeing, usetype
instead ofwhich
(and usetype -a
to see all possible results for a given command).