if ";" do all the stuff on the before do all the stuff on the after fork if kid for each arg if arg starts with "$" replace with getenv(that arg without $) if arg is ">" fdout = open for writing error check remove 2 args from the list dup2(fdin, 0); if arg == "<" fdout = open for writing error check remove 2 args from the list cerr < "I love cheese\n"; dup2(fdout, 1); if arg is a "|" pipe fork() if kid2 "ls" close pipefd[0] dup2(pipefd[1] , 1) exec stuff if parent "wc" close pipefd[1] dup2(pipefd[0] , 0) exec stuff build the args list for p in PATH exec print pancakes exit(3) void error(char *msg, bool flag) { if (flag) { perror(msg); exit(1); } } fd = open("fred.txt, O_RDONLY); error("Bad oipen", fd == -1); error("Bad open", fd = open("fred.txt", O_RDONLY) == -1); fd = open("fred.txt", O_RDONLY); if (fd == -1) { perror("crying"); exit(4); }