In bash, when running
myvar=val mycommand myargs
myvar=val will be added to the environment for executing
Suppose the the bash process calls
fork() to create a child process which will executes
mycommand is an external executable file or a script file.
When does adding
myvar=val to the environment happen, before or after the bash shell calls
fork()? In other words, which of the following two possibilities actually happens?
the bash process adds
myvar=valto its own environment, then calls
fork()to create a child process which will calls
myvar=valas part of the environment of the bash process is inherited into the environment of the child process. Upon finishing the execution of
mycommandand exiting of the child process, the bash process drops
myvar=valfrom its own environment.
the bash process calls
fork()to create a child process which will executes
mycommand, and the child process adds
myvar=valto its own environment and then calls
My question is motivated from Stephen's reply to my earlier post.
_is a special parameter which is set to the value of the last argument every time a command is parsed. It also has the special property of not being exportable, which is enforced every time a command is executed (see
bind_lastargin the Bash source code).
I am wondering that when a bash process executes a command, if bash doesn't add
_ to its own environment, why does it need to drop it from its own environment?