Bash – Which file is loaded and executed by a non-interactive non-login shell

bashinteractivelinuxshell

A non-login interactive shell (for example: when I open a Terminal window in Ubuntu) loads and executes the file ~/.bashrc.

Now when I execute a shell script, a non-interactive non-login shell process will be created that will run this shell script.

Is there a file that is loaded and executed by this non-interactive non-login shell?


Edit: The shell I am using is bash.

Best Answer

From man bash, in a non-interactive shell the BASH_ENV environment variable is evaluated and its content is sourced. So you could use that environment variable to specify a file with your environment settings.
By default no files will be sourced in non-interactive mode.

When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV
in  the  environment, expands its value if it appears there, and uses the expanded value as the name of a file 
to read and execute.  Bash behaves as if the following command were executed:
       if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the filename.
Related Question