Startup scripts (on boot)
Processes started by init usually have little or no pre-existing environment at all, although it depends on how they are invoked.
If they are invoked directly, i.e., forked and executed by the init daemon, $PATH
will not be set. If they are invoked via the shell, $PATH
may be set depending on the shell and how it is configured, but generally it still won't be set, which is why init scripts usually contain full paths.
Environment variables such as $PATH
are generally set in shell scripts which may be automatically sourced when the shell starts; for an explanation of how bash, e.g., does this, see INVOCATION in man bash
. For shells invoked non-interactively as sh
(i.e., most init scripts), there are no files automatically sourced.
Environment variables are also inherited, but unless init (the first process on the system) sets some, then its children (such as executed init scripts) won't inherit anything.
If a specific boot service needs the environment set up a certain way, it is the responsibility of that service to set up such an environment for itself. Traditionally this is done by initializing variables in an init script.
Processes running in (or sent to) the background
Processes inherit their environment from their parent (the process which started them). Sending them to the background does not change this.