Hi, i didn't know whether to put this under C or Shell scripting so i chose this one.
Well I am doing a piece of shell scripting and have written some code. and basically when i run it no prompt shows up so i cannot type commands like help or quit.
I run and write it in Unix / pico and i get warnings (which i heard we're okay) and no errors.
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
main()
{
char buf[1024];
char *args[64];
for(;;)
{
/*
*Prompt for and read a command.
*/
printf("Command:");
if(gets(buf) == NULL)
{
printf("\n");
exit(0);
}
/*
* Split the String into Arguments.
*/
parse(buf,args);
/*
* Execute the command.
*/
execute(args);
} // endof for loop
}
void help()
{
printf(“**********myshell usage/help options *************/n”);
printf(“help – prints the list of commands supported by the shell/n”);
}
/* parse -- Splits the command in buf into individual arguments */
parse(buf,args)
char *buf;
char **args;
{
while(*buf != NULL)
{
while((*buf == ' ') || (*buf == '\t'))
*buf++ = NULL;
/* Save the Argument. */
*args++ = buf;
/* Skip over the Argument. */
while((*buf != NULL) && (*buf != ' ' ) && (*buf != '\t'))
buf++;
}
*args= NULL;
}
/* execute -- spawns a child process and execute the program */
execute(args)
char **args;
{
int pid,status;
/* Get a child process */
if ((pid= fork())<0)
{
perror("fork");
exit(1);
}
if (pid==0)
{
if(strcmp(*args,"help")==0)
{
help();/*call the help function*/
}
else
{
execvp(*args,args);
}
perror(*args);
exit(1);
execvp(*args,args);
perror(*args);
exit(1);
}
/* The parent executes the wait.*/
while(wait(&status) !=pid)
/* empty */;
}
thats about it, i am sorry if thats alot of code or is unclear.
Basically i just need help figuring out why it's not creating a prompt
Thanks,