9.9. Environment variables

Programs installed on the system PATH (/bin, /usr/bin, /sbin, /usr/sbin, or similar directories) must not depend on custom environment variable settings to get reasonable defaults. This is because such environment variables would have to be set in a system-wide configuration file such as a file in /etc/profile.d, which is not supported by all shells.

If a program usually depends on environment variables for its configuration, the program should be changed to fall back to a reasonable default configuration if these environment variables are not present. If this cannot be done easily (e.g., if the source code of a non-free program is not available), the program must be replaced by a small “wrapper” shell script that sets the environment variables if they are not already defined, and calls the original program.

Here is an example of a wrapper script for this purpose:

  1. #!/bin/sh
  2. BAR=${BAR:-/var/lib/fubar}
  3. export BAR
  4. exec /usr/lib/foo/foo "$@"