为什么或为什么我的道路不被MacOSX所尊重? [英] Why or how is it that is my path is not being respected MacOSX?

查看:106
本文介绍了为什么或为什么我的道路不被MacOSX所尊重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

二进制文件怎么可能默认"执行-即由which命令返回的在我的路径中找到的第一个,实际上不是默认情况下实际执行的二进制文件吗? (我在2008 MacBook Pro上运行Mac OS X 10.5.)

How is it possible that the binary executed 'by default' -- ie. the first one found in my path, as returned by the which command, is in fact not the binary actually being executed by default? (I'm running Mac OS X 10.5 on a 2008 MacBook Pro.)

我刚刚通过运行brew install git

它在新路径中比旧二进制文件高或早的位置安装了新版本.但是,默认情况下不执行新版本.好像在我安装新二进制文件之前,shell已缓存了二进制文件的位置-但是which命令每次运行时都会解析路径.

It installed the new version in a location higher or earlier in my path than the old binary. However, the new version is not executed by default. It's as if the shell had cached the location of the binary before I installed the new one - but the which command parses the path every time it runs.

我想了解这里发生的事情,并了解如何刷新缓存"而不必注销或重新启动计算机.这就是我所看到的:

I'd like to understand what's going on here and learn how to flush the 'cache' without having to log out or restart the machine. This is what I'm seeing:

which git

返回

/usr/local/bin/git

同时

git --version

返回

git version 1.6.5

但是

/usr/local/bin/git --version

返回

git version 1.7.7

进一步检查,

which -a git

返回

/usr/local/bin/git
/usr/local/git/bin/git
/usr/local/bin/git
/usr/local/git/bin/git
/usr/local/bin/git
/usr/local/git/bin/git

(是的-我的路径设置有些冗余.)

(yeah - there's some redundancy in my path setup.)

/usr/local/git/bin/git --version

返回

git version 1.6.5

UPDATE -这是bash哈希的答案. (来自: 在bash中,";哪"给出了错误的路径-Python版本)

UPDATE -- here's the answer bash hashes. (from: In bash, "which" gives an incorrect path - Python versions )

type git

git is hashed (/usr/local/git/bin/git)

$ hash -d git

$ type git
git is /usr/local/bin/git

$ which git
/usr/local/bin/git

git --version
git version 1.7.7

推荐答案

在shell的给定实例中,确实缓存了二进制文件的路径.清除此问题的最简单方法是只打开一个新的终端窗口.但是,您也可以使用内置的hash shell(在有关详细信息,请阅读help hash)在现有窗口中将其清除.

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).

至于为什么which对于要执行的二进制文件与shell意见不同,这是因为which是驻留在/usr/bin/which并独立于shell解析PATH的程序.如果您想确切查看外壳程序正在查看的内容,请使用type而不是which(并使用type -a查看给定命令的所有可能结果).

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).

这篇关于为什么或为什么我的道路不被MacOSX所尊重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆