bash Mac 上的默认终端 $PATH 在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9832770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:50:03  来源:igfitidea点击:

Where is the default terminal $PATH located on Mac?

macosbashpath

提问by Andy

I have been looking throughout the system but I cannot find it. When I do echo $PATH I get the stuff I added, plus the default path. I do not have a .profile, and I do have a .bashrc, but the default path is not in there. I am looking for it just to know where it is located because all the tutorials explain that its in .profile... but what if you don't have one? Where is it located then? Anybody have any ideas?

我一直在寻找整个系统,但我找不到它。当我 echo $PATH 我得到我添加的东西,加上默认路径。我没有 .profile,我有 .bashrc,但默认路径不在那里。我正在寻找它只是为了知道它的位置,因为所有的教程都解释了它在 .profile 中......但是如果你没有一个怎么办?那么它位于哪里呢?有人有任何想法吗?

回答by beOn

If you do sudo man path_helper, it talks a bit about how it puts the path together. You might look in /etc/pathsand /etc/paths.d. I did, and found what I was looking for.

如果你这样做了sudo man path_helper,它会谈到它如何将路径组合在一起。您可能会查看/etc/paths/etc/paths.d。我做到了,并找到了我要找的东西。

回答by Adam Zalcman

Many system-wide settings including PATHare set in /etc/profilewhich is read in by bashat startup. On Mac OS X this file usually uses path_helperto set PATH. This utility in turn reads the information from other system configuration files under /etc(see path_helpermanpage).

许多系统范围的设置包括在启动时读取的PATH设置。在 Mac OS X 上,此文件通常用于设置. 该实用程序依次从其他系统配置文件中读取信息(请参阅手册)。/etc/profilebashpath_helperPATH/etcpath_helper

Note that even if you disable the reading of the initialization files by bash (e.g. with command-line options like --noprofile) it will still inherit the environment of the parent process.

请注意,即使您禁用 bash 读取初始化文件(例如使用命令行选项,如--noprofile),它仍将继承父进程的环境。

回答by Mike Taber

If you start at /etc/profile, it should look something like this:

如果您从 /etc/profile 开始,它应该如下所示:

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

It's testing to see if the file exists and if so, executes it. If you execute it by hand, you'll get something like this:

它正在测试文件是否存在,如果存在,则执行它。如果你手动执行它,你会得到这样的东西:

PATH="/usr/bin:/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"; export PATH;

I believe that's what you're looking for. So it comes from /etc/profile, which in turn calls an executable that sets the path.

我相信这就是你要找的。所以它来自/etc/profile,它反过来调用一个设置路径的可执行文件。

回答by Mauricio Mesones

The .profile file on Mac is located in your user folder: ~/Users/youruser/ However, the .profile file is hidden. You can press Command+shift+. (command, shift, dot) while on Finder to see them.

Mac 上的 .profile 文件位于您的用户文件夹中:~/Users/youruser/ 但是,.profile 文件是隐藏的。您可以按 Command+shift+。(command, shift, dot) 在 Finder 上查看它们。