Vijay Karode
Vijay Karode

Reputation: 1

Trying to learn the BASH Shell source code,but stuck with environment variables loading

I was curious about how the famous Bourne shell is written.So I started digging into the source code.I understand that,One of the initial things which bash does is it loads the ~/.bash_profile file for the user env. My question is how it loads the environment variables in the current shell.

  1. Does it fork and execute it?
  2. Does it read the bash_profile file and does putenv(),one for each variable?

In the source code bash-2.0/shell.c, I found a function call like,

maybe_execute_file ("~/.bash_profile", 1);

Even after digging further I was unable to get the exact logic as of how the values are pushed in environment.

Upvotes: 0

Views: 146

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122414

Neither - it executes it without forking (just like the . or source built in command). If it forked first then environment variable changes in the subshell wouldn't be visible in the original parent.

Upvotes: 1

Related Questions