If anyone is familiar with exec maybe you could help me out. I have a basic shell that I am trying to personalize. One of the features I want to include is that when the user inputs the command PATH they are then prompted for a directory which then is cat'ed to the end of linux's PATH variable. Here is a snippet of what I have so far:
It compiles fine and when I enter PATH it allows me to enter a variable but upon pressing return, I get a segmentation fault. I believe I am incorrectly using execve somehow, but I am still new to it so I am quite confused as to how to fix it.Code:char *t_PATH = (char *)malloc(sizeof(char) * 100); char c; if (strcmp("PATH", *g_argv) == 0) { printf("Please enter the directory you wish to add to PATH\n"); while(c != '\n') { c = getchar(); strncat(t_PATH, c, 1); } execve ("/bin/set PATH=$PATH:", t_PATH, ""); }
Anyone have any ideas?