#include <stdio.h>
int main()
{
setenv("PATH","/mypath",1);
printf("%s\n",getenv("PATH"));
return(0);
}
The above program outputs:
/mypath
If however you execute env in bash after your C program, you will get the PATH value which is set by default for bash.
$ env
...
PATH=/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/bin
...
This is because the environment variables are modified only for that particular process which is running the C program, & not for the process running bash.
Edit:
Writing env.c as:
#include <stdio.h>
int main()
{
printf("%s\n",getenv("PATH"));
return(0);
}
followed by:
$ gcc env.c
$ export PATH=/bin
$ ./a.out
gives:
/bin
I don't see why it should be any different. (Did you do all the steps that I have done above?)