People commonly put "important" environment variable settings in the /etc/profile file, but in lots of cases this is a mistake. But it's not usually obvious right away.
/etc/profile is processed at login time for all users, and of course anything set here is in effect for those login sessions. Things like the terminal type ($TERM) and the user command path ($PATH) are all appropriately set here.
But what about cron jobs? These do not get the benefit of /etc/profile, so any key environment variables (say, the java $CLASSPATH) have to be set more than once. This is a maintenance nightmare.
Better is to park the environment variable settings in a small file - say /etc/default/classpath - and source them where needed. From /etc/profile, from the cron jobs, anywhere. Then the file need be maintained just once, which gives future admins a fighting chance at getting it right.
In sh/ksh/bash, a file is sourced with the peculiar "dot" command:
. /etc/default/classpath
and it's processed as if it were included in the calling file.
This is a much more maintainable mechanism for dealing with systemwide variables.
Posted by Steve at August 25, 2002 10:40 PM | TrackBack