For setting global variables, there may a number of approaches, depending on your users' shells, and whether or not your system supports a
login.conf capability database or similar, which should apply, no matter what shell a user has.
The simplest approach is to add the definitions you want to the relevant system files under
/etc. Depending on the shells used on the system, you may find yourself setting up and managing multiple files. For example,
bash probably expect to find
zsh looks for
tcsh will look for something different.
If your system supports the capability database, you only need to modify one file, and all settings should be applied correctly. Under FreeBSD, for example, you'd add your envar definition to the
setenv capability for any class of user that needs it:
Rebuild the database, and at next login
$FOO should be set.
If you don't have
login.conf, there may be a different method of globally configuring users' environments on your system.
To set variables for a particular user, I think you'd need to use the first approach, where you'd test the value of the
$USER variable in a
case statement or similar construct supported by the particular shell. For example, this should work in
sh and compatible:
case $USER in