OS X Mountain Lion:path_helper如何工作? [英] OS X Mountain Lion: how does path_helper work?

查看:117
本文介绍了OS X Mountain Lion:path_helper如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过自制软件安装了rbenv,现在我不知道path_helper为什么将〜/.rbenv/shims放在路径的末尾而不是开头.最重要的是,path_helper是如何获得此信息的?

I installed rbenv through homebrew, and now I don't know why path_helper put ~/.rbenv/shims at the end of the path instead of the beginning. And most importantly, how did path_helper get this information?

根据path_helper的手册页,它从/etc/paths和/etc/paths.d中的文件读取条目.但是我找不到那里的字符串".rbenv/shims".

According to the man page of path_helper, it reads entries from /etc/paths and from files in /etc/paths.d. But I cannot find the string ".rbenv/shims" there.

~% cat /etc/paths 
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
~% ls -la /etc/paths.d 
total 0
drwxr-xr-x    2 root  wheel    68 Jun 21 03:16 .
drwxr-xr-x  107 root  wheel  3638 Sep 10 09:59 ..
~% /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/gordon/.rbenv/shims"; export PATH;

推荐答案

我怀疑您的.bash_profile.bashrc正在添加 .rbenv/shims到您的PATH,并且在之前的某个时间运行 path_helper在外壳启动期间被调用.

I suspect that your .bash_profile or .bashrc is adding .rbenv/shims to your PATH, and that is running at some point before path_helper is invoked during the shell start-up.

path_helper的手册页打开:

The man page for path_helper opens with:

 The path_helper utility reads the contents of the files in the directo-
 ries /etc/paths.d and /etc/manpaths.d and appends their contents to the
 PATH and MANPATH environment variables respectively.

此处的关键点是path_helper实用程序旨在 将内容添加到现有的PATH设置中,而不要替换它们. (在 实际上,它真正要做的是 prepend 内容,而不是附加内容, 对于PATH变量来说很重要...)

The crucial point here is that the path_helper utility is intended to add contents to an existing PATH setting, not replace them. (And in actuality, what it really does is prepend contents, not append them, which matters for PATH variables...)

因此,如果我从PATH上的条目开始,则由 path_helper将确保条目在生成的PATH上继续.

So, if I start out with an entry on my PATH, the setting generated by path_helper will ensure that entry continues on the PATH it generates.

% echo $SHELL
/bin/bash
% uname
Darwin
% /usr/libexec/path_helper 
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"; export PATH;
% PATH="" /usr/libexec/path_helper 
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"; export PATH;
% PATH=foo /usr/libexec/path_helper 
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo"; export PATH;

请注意,即使foo已包含在我的PATH的最后一行中,即使 /etc/paths/etc/paths.d/*的内容未更改.

Note that foo has been included in my PATH in the last line, even though the contents of /etc/paths and /etc/paths.d/* have not changed.

同时,path_helper实用程序似乎也要注意不要 产生具有重复条目的路径;它删除重复的条目 将/etc/paths/etc/paths.d/*与当前 PATH.

At the same time, the path_helper utility also seems to be careful not to produce paths with duplicate entries; it removes duplicate entries after concatenating /etc/paths and /etc/paths.d/* and the current PATH.

后一个细节可能特别令人困惑,因为它可能导致 与原始PATH设置(!)相比,条目重新排序.

This latter detail can be especially confusing since it can cause entry reorderings compared to the original PATH setting (!).

以下是此行为的一些示例:第一种情况显示重复的foo被删除.第二种和第三种情况说明了条目重新排序:两种情况下生成的PATH都相同,但是在第三种情况下,/usr/bin条目已从foobar之间移动到了PATH. (此重复项的删除似乎仅基于一对条目上的简单字符串匹配,如下面的第四种情况所示,其中字符串/usr/bin/保留在foo/bar之间.)

Below are some examples of this behavior: The first case shows a duplicate foo being removed. The second and third case illustrate entry reordering: the generated PATH is the same in both cases, but in the third case, the /usr/bin entry has been moved from in-between foo and bar to the front of the PATH. (This duplicate-entry removal seems to be based on just simple string-matching on the pairs of entries, as illustrated by the fourth case below where the string /usr/bin/ remains between foo/ and bar.)

% PATH=foo:foo /usr/libexec/path_helper 
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo"; export PATH;
% PATH=foo:bar /usr/libexec/path_helper 
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo:bar"; export PATH;
% PATH=foo:/usr/bin:bar /usr/libexec/path_helper 
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo:bar"; export PATH;
% PATH=foo/:/usr/bin/:bar /usr/libexec/path_helper 
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo/:/usr/bin/:bar"; export PATH;

最后,在应得的信用额中给予信用: 尽管以上所有命令序列都是我自己研究的结果,但最初阅读本说明

Finally, to give credit where credit is due: While all of the command sequences above are the result of my own investigations, I was originally inspired to look into the behavior of path_helper after reading the note here, which pointed out that path_helper reuses the PATH environment variable set by the parent process.

这篇关于OS X Mountain Lion:path_helper如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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