Strange behaviour for setenv & getenv in OS X Yosemite

你说的曾经没有我的故事 提交于 2019-12-31 04:25:07

问题


When I set an environment variable

launchctl setenv FOO test

I can fetch the value by

launchctl getenv FOO

which returns me 'test', but a simple

echo $FOO

doesn't substitute, the result is empty. In same terminal as well as in new terminal.

Background: Yosemite 10.10 doesn't support /etc/launchd.conf anymore for system wide settings, so Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra? looks pretty promising, but I need the access to the env vars via $VARNAME, which doesn't work in my case.


回答1:


As I wrote in section Issues / problems here in order your env variables were correctly taken by applications after system reboot you will need:

  • either login twice: login => logout => login
  • or close & re-open applications manually, where env variables should be taken
  • or do NOT use feature "Reopen windows when logging back".

This happens due to Apple denies explicit ordering of loaded services, so env variables are registered in parallel with processing of the "reopen queue".



来源:https://stackoverflow.com/questions/27045137/strange-behaviour-for-setenv-getenv-in-os-x-yosemite

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