As mentioned above; export
is not an executable file, it is a built-in bash command. The exec
variant functions by their nature, replace the current process image with a new process image. Therefore, you can only use exec
variants on executable programs or processes. In Unix/Linux operating systems, every process has its own environment variables. You can get those key-value pairs by reading environ
variable, which is declared in unistd.h
header file as an extern
char**
pointer-to-pointer variable.
Environment variables are inherited by child process created by the parent process. If you use setenv
/putenv
functions to create a new environment variable in your program, this new variable will only be granted in your parent and nested child processes until they exit or terminate. If you would like to make these variables permanent, you will need to set them in a startup shell script.
In Linux systems, bash runs the following script files before it shows up:
- /etc/profile
- /etc/bashrc
- ~/.bash_profile
If you embed your environment variables as export key=value
commands in the shell script, which is going to be started up by bash that your main program will run on top, you might access them from your program or terminal itself.