Program:
#include<stdio.h>
#include<unistd.h>
int main()
{
char s[100];
printf("%s\n",getcwd(s,100));
chdir("..");
printf("%s\n",getcwd(s,100));
return 0;
}
Output:
$ ./a.out
/home/guest
/home
$
The above program changes the working directory of a process. But, it doesn't change the working directory of current shell. Because when the program is executed in the shell, the shell follows fork on exec mechanism. So, it doesn't affect the current shell.
Is there any way to change the current working directory of the shell via these program like a built-in (cd, echo) command used by the shell?