Hi guys,
So my code is below. This is a simplified version of the shell... It does not continue for ever... I guess its actually rather a program to accept a command.. has the fork and the execve etc. Anyways when i compile it and run it in the terminal for some reason only '/bin/echo "enter text here"' works...
But when i try to use a command like /bin/ls "directory" it wont work.. but when i call /bin/ls "directory" in the terminal (not in my half-shell) it works perfectly fine.. So i dont know if this could be a problem with my code.
Thanks
Guys
#include <string.h>
#include <errno.h>
#include <stdio.h>
#define TRUE 1
int main()
{
int n = 0;
int status;
char *argv[100];
char temp[256];
fgets(temp, sizeof(temp), stdin);
argv[n++] = strtok (temp," ");
while (argv[n-1] != NULL)
argv[n++] = strtok (NULL, " ");
// This is merely to print out what got splitted for the tokens////////////////////////////
int b=0;
while (argv[b] != NULL)
{
printf ("%s\n", argv[b]);
b++;
}
//////////////////////////////////////////////////////////////////////////////
if (fork() != 0)
{
waitpid(-1, &status, 0);
}
else
{
if (execve(argv[0], argv, 0) == -1) /* execute command */
printf(": %s\n", strerror(errno));
}
}