A login sh
session reads the user's ~/.profile
upon invocation. If the ENV
variable is set to a filename after doing that, and if that file exists, the shell will use that file to further initialize the login session.
Interactive shells that are not login shells will only use $ENV
if ENV
is set, but will not read ~/.profile
.
Non-interactive shell should not use either of these two files.
Usually, one exports ENV
at the end of one's ~/.profile
:
ENV="$HOME/.shrc" # for example
export ENV # may be done as export ENV="..." too, in most shells.
This is, for example, what bash
does if it's invoked as sh
or with bash --posix
.
One may use these two files (~/.profile
and $ENV
) for whatever one wishes, but the profile is where you might want to set and export environment variables that only needs to be set once (PATH
etc.), fire up any fetchmail
process or other user daemon that you wish to use etc., while the $ENV
file is where you set up specific things for this particular shell session/TTY, such as setting GPG_TTY
(if you're using GnuPG), setting up aliases (since aliases are not inherited by subshells) etc.
The ksh93
shell uses ~/.profile
and $ENV
by default, but interprets $ENV
in a specific way. If $ENV
starts with /./
or ././
, then no system-wide configuration file will be used (e.g. /etc/ksh.kshrc
).
The file ~/.login
is not used by sh
, unless ENV
is set to this filename or it is explicitly sourced from ~/.profile
or $ENV
.