1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
ctp
  • 1,077
  • 1
  • 10
  • 28
  • 2
    Have you tried restarting Terminal.app? – Mats Nov 20 '14 at 16:59
  • That was the trick :) I just opened a new tab or window but didn't killed the old Terminal.app before. Now all's fine. Thanks! – ctp Nov 20 '14 at 22:53

1 Answers1

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

Community
  • 1
  • 1
ursa
  • 4,404
  • 1
  • 24
  • 38
  • I even read that couple of times but misunderstood close & re-open for Terminal.app. It's not about closing one terminal window and opening a new one but about quitting Terminal.app as app. Which makes sense afterwards :) – ctp Nov 21 '14 at 00:39