Invocation
If no arguments are present and if the standard input of the shell is
connected to a terminal (or if the -i option is set), the shell is
considered an interactive shell. An interactive shell generally prompts
before each command and handles programming and command errors
differently (as described below). When first starting, the shell
inspects argument 0, and if it begins with a dash (‘-’), the shell is
also considered a login shell. This is normally done automatically by
the system when the user first logs in. A login shell first reads
commands from the files /etc/profile and then .profile in a user's home
directory, if they exist. If the environment variable ENV is set on
entry to a shell, or is set in the .profile of a login shell, the shell
then subjects its value to parameter expansion and arithmetic expansion
and reads commands from the named file. Therefore, a user should place
commands that are to be executed only at login time in the .profile file,
and commands that are executed for every shell inside the ENV file. The
user can set the ENV variable to some file by placing the following line
in the file .profile in the home directory, substituting for .shrc the
filename desired:
ENV=$HOME/.shrc; export ENV
The first non-option argument specified on the command line will be
treated as the name of a file from which to read commands (a shell
script), and the remaining arguments are set as the positional parameters
of the shell ($1, $2, etc.). Otherwise, the shell reads commands from
its standard input.
Unlike older versions of sh the ENV script is only sourced on invocation
of interactive shells. This closes a well-known, and sometimes easily
exploitable security hole related to poorly thought out ENV scripts.