For this project, you will design and implement a simple command-line shell, similar to bash or zsh. Your program, mysh, will provide interactive and batch modes, both of which will read and interpret a sequence of commands. This project will provide experience of Posix (unbuffered) stream IO Reading and changing the working directory Spawning child processes and obtaining their exit status Use of dup2() and pipe() Reading the contents of a directory Extensions In addition to the requirements that all projects must satisfy, this assignment includes five extensions (see section 3). For full credit, your project must implement two of these extensions. 1 Overview Your program mysh takes up to one argument. When given one argument, it will run in batch mode. When given no arguments, it will run in interactive mode. For full credit, your program must have one input loop and command parsing algorithm that works for both modes. Batch mode When called with an argument, mysh will open the specified file and interpret its contents as sequence of commands (see section 2). The command are given by lines of text, separated by newlines. mysh will execute each command as soon as it is complete, before proceeding to execute the next command. mysh terminates once it reaches the end of the input file or encounters the command exit. Interactive mode When called with no arguments, mysh will read commands from standard input. Before reading a command, mysh will write a prompt to standard output. After executing the command, mysh will print a new prompt and read the next command. To ensure that prompts are printed appropriately, mysh must be careful not to call read() again if a newline character has already been entered. mysh terminates once it reaches the end of the input file or encounters the command exit. In this mode, mysh should print a greeting before the first prompt and a message when terminating normally. The format of these are left to you. Prompt format When running in interactive mode, mysh will print a prompt to indicate that it is ready to read input. The prompt is normally the string mysh> (note the trailing space). If the last command failed (meaning its exit status was non-zero), the prompt is the string !mysh> (that is, it is preceded by an exclamation point). Usage Batch mode: $ cat myscript.sh echo hello $ ./mysh myscript.sh hello $ Interactive mode: $ ./mysh Welcome to my shell! mysh> cd subdir mysh> echo hello hello mysh> cd subsubdir mysh> pwd /current/path/subdir/subsubdir mysh> cd directory_that_does_not_exist cd: No such file or directory !mysh> cd ../.. /current/path$ exit mysh: exiting $ Note the exclamation point after a failed command. 2 Command format A mysh command comprises one or more tokens. Tokens are sequences of non-whitespace characters, and are usually separated by whitespace. The exceptions are |, <, and >, which are considered tokens by themselves. Thus, a string foo bar tokens introduce file redirection (see section 2.3.