Posts

Showing posts from January 20, 2019

Are processes run from Bash run in a “sub shell”?

Image
1 When I run an executable (like a.out) from a Bash shell, is that executable run in some kind of "sub" shell, i.e. different from the shell at which I'm typing? I'll try illustrate my question with an example. The following program gets and prints the value of an environment variable, changes it, then re-gets and prints it again: #include <iostream> #include <string> #include <cstdlib> int main( int argc, char* argv ) { std::string str( getenv( "FOO" ) ); std::cout << str << std::endl; setenv( "FOO", "bar", 1 ); str = getenv( "FOO" ); std::cout << str << std::endl; return 0; } Now, notice the output when I run the following at my Bash prompt: >unset FOO && export FOO=foo &&am