I tried to remove all environment variables for the current shell and for the subshell:
bash-3.2$ unset $(env | cut -d= -f1) OLDPWD
bash-3.2$ export
bash-3.2$
For shell, everything turned out as intended, but there were some problems with subshell:
bash-3.2$ /bin/bash
bash-3.2$ export
declare -x OLDPWD
declare -x PWD="/Users/alex"
declare -x SHLVL="1"
declare -x _="/bin/bash"
bash-3.2$ env
PWD=/Users/alex
SHLVL=1
_=/usr/bin/env
- bash has created variables. There is no file in the home directory .bashrc and other files from which bash can take data at startup. Where did he get these variables from?
- How can bash execute non-builtin commands if PATH is not set?
CodePudding user response:
bash has created variables. ... Where did he get these variables from?
From Bash. Like literally, from Bash source code.
https://github.com/bminor/bash/blob/f3a35a2d601a55f337f8ca02a541f8c033682247/variables.c#L858
How can bash execute non-builtin commands if PATH is not set?
When PATH is not set, Bash uses some "default PATH". There is a macro in source code, and it can be changed with compile ./configuration option.
https://github.com/bminor/bash/blob/f3a35a2d601a55f337f8ca02a541f8c033682247/config-top.h#L66 and https://github.com/bminor/bash/blob/f3a35a2d601a55f337f8ca02a541f8c033682247/variables.c#L495
Use env -i
to run something in blank environment.