Question: Im trying to read an exported variable in c but i cant, there are two scenarios.

**A)**

1) i have a sh file like:

```
#!/bin/bash
timeout 3s ./program
export OUT=$?

```

2) then i run: `. file.sh`

3) and when i read the var in c with:

`getenv("OUT")` yes, i read it.

**B)**

1. in c: `system("/bin/bash -c '. PathOfFile/file.sh'");`
2. `getenv("OUT")` . i cant access to OUT

i need run the sh file in c and read the var also in c

thanks

Answer: 
The environment in POSIX is inherited by new processes (created by fork) aka child processes. But when you change the environment in a child process and that process ends there is nothing which saves the environment or causes the parent process to get any information other than the exit code of the child process. If you want to save something from the child process you have to make that happen with some form of IPC, from saving it in a file to using sockets or memcached.
You must understand the concept of process. `system("/bin/bash -c '. PathOfFile/file.sh'");` will create a new process for you to run your file.sh, and the `OUT` environment variable is declared in your file.sh, in other word, it exists in the context of the new process. However, your just can't get the environment variable in your C code (which call `system` function), because it's totally different process context. Of course you can still use IPC methods to get this environment variable if you want.