In said:
please do let me know how i can change the directory through my
program and retain it too after i exit; if there's a way to do it.
The current working directory is a property of the program. It is
not passed back to the "parent" process, so this piece of information
is normally lost when the program terminates.
It is always possible to do something about it, just don't expect it
to happen by magic:
fangorn:~/tmp 1921> pwd
/afs/ifh.de/user/d/danpop/tmp
fangorn:~/tmp 1922> cat test.c
#include <stdio.h>
#include <unistd.h>
char buff[FILENAME_MAX];
int main()
{
chdir("/usr/bin");
if (getcwd(buff, sizeof buff) != NULL) puts(buff);
else puts("unknown");
return 0;
}
fangorn:~/tmp 1923> gcc test.c
fangorn:~/tmp 1924> cd `./a.out`
fangorn:/usr/bin 1925> pwd
/usr/bin
Of course, this approach works only as long as you don't use stdout for
any other purposes...
Dan