#include <stdio.h>
#include <unistd.h>     /* for execvp */
#include <stdlib.h>	/* for malloc */
#include <readline/readline.h>

/* Another exec example - this one reads comands
   from the command line and then forks() and the 
   child execs the command. The parent waits for the child
   to die before running the next command.

   This mini-shell does not support command line
   options, so the commands must be a something that can
   run without any (so it will run "ls", but not "ls -al").

   uses gnu readline to read from stdin, so the readline
   library must be included on the gcc command line (and the
   appropriate include and library paths need to be included
   to compile on BSD).

   No readline history is supported in this program...

*/

int main() {
  char *s;
  int status;
  while (s = readline("> ")) {
	if (fork()) {
	  /* parent waits for child */
	  wait(&status);
	} else {
	  /* child execs the command (or tries to) */
	  if (execlp(s,s,NULL)) {
		perror("Huh?");
	  }
	  /* we only get here is exec failed! */
	  exit(1);
	}
  }
  return(0);
}



