Creating new, system-wide env variables via shell script (OSX, El Capitan)

This is frustrating. I want to create a new persistent and system-wide environment variable via a shell script on OSX (El Capitan)

The export -command only works for the current session (so it’s needed internally by the script but doesn’t write anything that is persistent on the system)
…and then what?

Googling this I find:
-People talking about appending the path to .bash_profile, manually… I find nothing about appending to this file via shell script
-People saying .bash_profile only applies to shells (so say, any apps that need to know my custom environment variable will still be clueless)
-People talking about appending the path to enrivonment.plist (turns out this is for older versions of OSX - the file is no longer used)

Add to the confusion that people fail to provide info on what shell they are using when providing code examples.

[warning: untested – i’m on my windows box at work]

If you do export in your .bashrc you’ll have it in bash; if you launch from a bash session that has sourced your .bashrc you’ll have the var.

If you put it in /etc/profile you should get it for all shells, including bash : http://galerialogo.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/

If you want it for everything its in /etc/launchd.conf : http://apple.stackexchange.com/questions/107787/how-to-set-system-wide-environment-variables-on-os-x-mavericks

It’s easier to think in the direction that there’s no such concept as system-wide env variables, and configure them as late as launch script of your own application. Much easier to maintain values this way.

The process launching another process is responsible/capable of setting the environment. .bashrc might or might not be used, depending how you launch it, as well as other configuration methods previously listed.

launch.conf has been depricated

Here are some newer ways to set global env variables whichw work in el cap: