I am trying to create a simple shell in C. I am having issues with using the execve() function. So I have my arguments declared as char *cmdargs[10]; which holds the arguments such as -a or -l. However, it does not work with my execute function and I assume that because this array does not have the command as the first argument, and I am not sure how to add the command to the first of the array. Assuming now the array is
cmdargs[] = {"-a", "-l", NULL};
I want to the array to be
cmdargs[] = {"ls", "-a", "-l", NULL};
However, the command is declare as a pointer: char *cmd;
so how I can add this pointer to the beginning of my array.
Here is how you can do if your array is *cmdargs[] = {"-a", "-l", NULL};
I used execv here for simplicity: execve ask for a null terminated env array as last argument