I used the setenv()
function to add a new env variable —
ex:
setenv("HELLO", "env", 1)
Why can't I find the new environment variable I've created whenever I type the env command in the terminal?
I used the setenv()
function to add a new env variable —
ex:
setenv("HELLO", "env", 1)
Why can't I find the new environment variable I've created whenever I type the env command in the terminal?
Every process has its own set of environment variables. When you programmatically set them for a particular process, you are only setting them for that process (and any processes it runs). When the process exits, then those settings disappear.
If you want for your terminal session you need to set in the command shell for the terminal session.
See also How to use setenv() to export a variable in c++?
Also see Why the environment variable is unset after using setenv( )