/* * sh1.c: sample version 1 of a UNIX command shell/interpreter. * Stefan Brandle, COS 421, Feb 2000. Mod Feb 2001. */ #include #include #include int main() { char line[256]; char prompt[] = "sh1 % "; /* spit out the prompt */ printf("%s", prompt ); /* Try getting input. If error or EOF, exit */ while( fgets(line, sizeof line, stdin) != NULL ) { /* fgets leaves '\n' in input buffer. ditch it */ line[strlen(line)-1] = '\0'; /* This is where I take the easy route. fork(), execvp() & co. go here in your version*/ system( line ); printf("%s", prompt ); } return 0; }