PATH is getting set somewhere other than launchd.conf and I don't know where

风格不统一 提交于 2020-01-01 06:49:13

问题


The question of how to set PATH for all programs in a user session (not just Terminal) has come and been addressed. So I changed both /etc/launchd.conf AND /etc/paths, just to make sure everything was ok. However, I am still getting a different PATH envar when I launch Terminal than what I'm expecting (I'm not at all sure how to test PATH from another application.)

Here's what's in /etc/launchd.conf:

setenv PATH /sw/bin:/sw/sbin:/sw/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11/bin:/opt/local/bin:/opt/local/sbin

Here's what's in /etc/paths:

.
$HOME/bin
/sw/bin
/sw/sbin
/sw/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

Plus a couple of files in /etc/paths.d/:

X11:

/usr/X11/bin

opt:

/opt/local/bin
/opt/local/sbin

Now, what I get when I launch a fresh Terminal is:

miishka:~ tamara$ echo $PATH
 /usr/bin:/bin:/usr/sbin:/sbin:.:/Users/tamara/bin:/sw/bin:/sw/sbin:/sw/local/bin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/opt/local/sbin
miishka:~ tamara$ 

I've checked my .bashrc and .bash_profile, I have no .profile, and I've checked /etc/profile and /etc/bashrc and NONE of them touch the PATH envar.

I'm so stumped.


回答1:


man path_helper

This thing drove me crazy. I use zsh, and in /etc/zshenv i found it.

# system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

path_helper(8) actually has a useful purpose, I think. It's negated by the usual ultra vague sysadmin info from apple. look for path_helper(8) in your shell init file, in /etc, even if you are using macports, like I am. That might help.

Otherwise, you can try setting environment in:

 /etc/launchd.conf

But of course, the man page is not definitive. http://developer.apple.com is excellent documentation, but usually I want better man pages, not precise memory locations.

Finally, you can set them on on the loginwindow which reads:

 ~/.MacOSX/environment.plist

Now, to me, it seems odd to have several ways to do this, but... well hell, it is odd. They made a decent init replacement, it is to be the one process to rule them all, but nope, many jobs get run outside of it. Good luck. You should be able to get a $VAR into your gui using one of these methods.

Ah, http://developer.apple.com/library/mac/#qa/qa1067/_index.html.

OSX has various sessions and domains. To be precise, from

 man launchctl

Sessions:

Currently known session types include: Aqua, LoginWindow, Background, StandardIO and System.

Domains:

Look for plist(5) files ending in *.plist in the domain given. Valid domains include "system," "local," "network" and "all."

It makes sense when you read it.

Ugh. launchd always gets to me.

EDIT: https://serverfault.com/questions/16355/how-to-set-global-path-on-os-x/277034#277034

Again alleges that /etc/launchd.conf is where files get the path.

So I ran

 opensnoop -g -c -f /etc/launchd.conf

and opened Terminal, iterm, safari, keychain... nada. none of them opened that file.

EDIT: However, after watching the google video on launchd i ran

 launchctl export 

which showed me

PATH="/usr/bin:/bin:/usr/sbin:/sbin"; export PATH;
TMPDIR="/var/folders/YH/YHFe3+5RHmuxft5hr1XZTk+++TI/-Tmp-/"; export TMPDIR;
SHELL="/opt/local/bin/zsh"; export SHELL;
HOME="/Users/kb"; export HOME;
USER="kb"; export USER;
LOGNAME="kb"; export LOGNAME;
DISPLAY="/tmp/launch-dcQkBh/org.x:0"; export DISPLAY;
SSH_AUTH_SOCK="/tmp/launch-czhyqj/Listeners"; export SSH_AUTH_SOCK;
Apple_PubSub_Socket_Render="/tmp/launch-TI7lbI/Render"; export Apple_PubSub_Socket_Render;



sudo launchctl export 

which changes my context to the System context, instead of my Aqua context as a user, returned

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

So the context really does matter, in other words, as does the session a command is run in.

Documentation for this tool, this init replacement, the most important daemon in apple, the one daemon to rule them all, is piss poor. Piss. Poor.



来源:https://stackoverflow.com/questions/6555751/path-is-getting-set-somewhere-other-than-launchd-conf-and-i-dont-know-where

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!