Is it possible to set up an envinronment variable that can be accessible from any shell, not an specific one, and that doesn't decay as soon as your session ends?
I'd like to set up a NODE_ENV
variable system wide, how could I achieve that?
environment-variables
Is it possible to set up an envinronment variable that can be accessible from any shell, not an specific one, and that doesn't decay as soon as your session ends?
I'd like to set up a NODE_ENV
variable system wide, how could I achieve that?
Best Answer
If all the shells you're interested in are Bourne-compatible, you can use
/etc/profile
for this purpose.The header of
/etc/profile
:To ensure you've got
csh
andtcsh
covered, you can also add your variables to/etc/csh.login
.The header of
/etc/csh.login
:For
zsh
, you want/etc/zshenv
.For ease of maintenance
I would write all the variables you want in a single file and write a simple Perl (or other) script that would read these variables and update the relevant files for all the shells.
Something like the following in Perl should work:
You can use a delimiter other than
,
to delimit variables and values as long as this delimiter isn't allowed in variable names.This can be further tidied up by inserting unique delimiters around the portion you want your script to write in each file so that each time you use the script to update the files, it doesn't duplicate previous entries but substitutes them in situ.