1

Does the following show the default environment variable in a bash shell without running any startup file?

$ env -i bash --noprofile --norc
$ export
declare -x OLDPWD
declare -x PWD="/home/t"
declare -x SHLVL="1"

(Note that set will give a much longer list of default shell variables which might or might not be environment ones.)

When and how were the three environment variables created and exported?

Who created them, bash itself, or some implicit startup files which I didn't exclude when starting bash?

My question is inspired by What are the environment variables by default?

Thanks.

1
  • They are created by bash itself.
    – user232326
    Commented Apr 22, 2018 at 0:59

1 Answer 1

4

When I'm curious what an open source program is doing, I'll look at the source code (and documentation, and experimentation). Looks like you've found a pretty good list, based on searching for set_auto_export ( in bash's source code for variables.c

These are inside initialize_shell_variables(), which is called from shell_initialize() in shell.c, which itself is called from main() in shell.c.

You can even find evidence of $PATH and $TERM being marked for export at one point in time, but now ifdef'd out.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .