rootkea
rootkea

Reputation: 1484

Controlling the environ passed to child process by bash

I am using x86_64 GNU/Linux with bash

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    system("set > setc");                           // A subset of `$ set`

    return 0;
}

I can see the file setc contains a subset of $ set.
I am feeling curious as to know how the shell (parent process) decides what to supply to child process and what not to?
What if I want to supply more environ variables to child process? How one can control that?

Upvotes: 0

Views: 57

Answers (1)

user4098326
user4098326

Reputation: 1742

A shell variable can be either exported or not exported. The shell will only pass exported variables to child processes. In bash, you can export a variable(for example, $var) by executing export var.

Upvotes: 2

Related Questions