I cannot make sense of the results below:
/tmp/% /usr/bin/env -i /bin/bash --norc --noprofile
bash-5.0$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.
I expected PATH to be empty.
Actually, in a way it is:
bash-5.0$ /usr/bin/printenv
PWD=/tmp
SHLVL=1
_=/usr/bin/printenv
So there's no PATH in the environment, but a non-empty PATH variable is still defined, and can be used by the shell to resolve commands:
bash-5.0$ which ls
/bin/ls
I realize that I can force /usr/bin/env to have an empty PATH like this:
/tmp/% /usr/bin/env -i PATH= /bin/bash --norc --noprofile
bash-5.0$ /usr/bin/printenv
PWD=/tmp
SHLVL=1
PATH=
_=/usr/bin/printenv
bash-5.0$ echo $PATH
bash-5.0$
I have two problems with this approach: 1) PATH is shows in the output of /usr/bin/printenv; I'd prefer it if it were completely gone; 2)the situation described above is not unique to PATH; after /usr/bin/env -i a lot of variables in the resulting shell session are still defined.
Q: What is the simplest way to start an interactive /bin/bash session with the least possible number of variables defined (whether in the environment or not)? 1
(Though I've phrased this question in terms of bash, I'm also interested in any related info regarding zsh.)
1 I am aware of the fact that many programs will not function normally, or function at all, if some variables are undefined. I do not intend to use such minimal shell sessions for anything other than for troubleshooting, diagnostics, and the like.
whichisn't a builtin. that may or may not affect your results, butcommand -vwill at least report what the shell actually thinkswhichis a builtin inzsh(like intcsh).info zsh 'Parameters Set By The Shell'