Even if Bash does not inherit any environment variables from the parent process, bash will create three environment variables, respectively:
$ env-i BASH-C Export Declare-x oldpwd Declare-x pwd= "/" Declare-x shlvl= "1" |
Shlvl
If the parent process passes the SHLVL environment variable, Bash accumulates 1 on that value and assigns an initial value of 1 if there is no pass:
$ env-i shlvl=22 bash-c ' echo $SHLVL ' 23 $ env-i bash-c ' echo $SHLVL ' 1 |
Pwd
If the parent process passes the PWD environment variable, and the value of the environment variable is the path to the current directory and is an absolute path, bash inherits the value directly, otherwise bash calls the GETCWD C function to get the current working directory assigned to PWD.
$ env-i pwd=/bash-c ' echo $PWD ' / $ env-i pwd=/etc bash-c ' echo $PWD ' # is not the path of the current directory / $ env-i pwd=. Bash-c ' echo $PWD ' # is the path to the current directory, but is a relative path. / |
Oldpwd
If the parent process passes the OLDPWD environment variable, Bash empties the value of the variable directly.
$ env-i oldpwd=/etc bash-c ' echo $OLDPWD ' $ env-i oldpwd=/etc ksh-c ' echo $OLDPWD ' /etc $ env-i oldpwd=/etc csh-c ' echo $OLDPWD ' /etc $ env-i oldpwd=/etc zsh-c ' echo $OLDPWD ' / |
It can be seen that unlike Bash,ksh and csh inherit that value directly, and zsh overwrites the value of the inherited OLDPWD variable with the value of the current working directory.
Someone raised the question on Bug-bash. Http://lists.gnu.org/archive/html/bug-bash/2015-11/msg00115.html,Bash the author says it will try to change this behavior in the next version, But not copy Ksh and csh practice, Ksh and CSH simply inherit the value of oldpwd, do not judge that the value is not a valid directory path of existence:
$ env-i oldpwd=2333 ksh-c ' echo $OLDPWD ' 2333 $ env-i oldpwd=2333 csh-c ' echo $OLDPWD ' 2333 |
The Bash author says he is prepared to judge if it is a legal directory path to inherit.
Bash will empty the oldpwd inherited from the parent process.