#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

/*Carles Pina i Estany - carles@pinux.info
 * Febrer 2004*/

//Petita "simulació" de un interpret de comandes
//faltaria afegir-hi més comandes, opcions, redireccions, etc.

int main () {
	int opcio;
	int pid;

	printf("EL MINI-SHELL\n");
	printf("1: ls ||  2: df || 3: exit\n");

	while(opcio!=3) {
		scanf("%d",&opcio);

		printf("Has seleccionat: %d\n",opcio);

		switch(opcio) {
			case 1:
			pid=fork();
			if (pid==0) {
				//Sóc el fill
				execl("/bin/ls","/bin/ls",NULL);
			}
			waitpid(&pid);
			break;
			
			case 2:
			pid=fork();
			if (pid==0) {
				//Sóc el fill
				execl("/usr/bin/du","/usr/bin/ls",NULL);
			}
			waitpid(&pid);
			break;
		}
	}
	return (0);
}
