I made a simple minishell in C and it works, except for the cd
command. When I try to run it nothing happens except it creates a child process that never actually e
cd
is necessarily a shell built-in, not an external utility. You want to change the current working directory of the current process (the shell itself), not of a child process. Call chdir instead of forking a child process.
Separately, check execvp for errors and defensively terminate the child after a failed exec. You'd have seen an informative error if you had done so:
... (child) ...
execvp(Array_arg[0], Array_arg);
perror("Error - exec failed"); // If we are here, we did *not* replace the process image
exit(0);