Unix shell with redirects and pipes
The purpose of this assignment is to learn to develop multi-process programs. You are expected to extend the myshell.c program and add pipelines and I/O redirections. In particular, your shell program should recognize the following:
- > – Redirect standard output from a command to a file. Note: if the file already exists, it will be erased and overwritten without warning. For example,COP4338$ ls > 1
COP4338$ sort myshell.c > 2
Note that you’re not supposed to implement the Unix commands (ls, sort, …). You do need to implement the shell that invoke these commands and you need to “wire” up the standard input and output so that they “chain” up as expected. - >> – Append standard output from a command to a file if the file exists; if the file does not exist, create one. For example,COP4338$ sort myshell.c >> 1
COP4338$ echo “Add A Line” >> 1 - < – Redirect the standard input to be from a file, rather than the keyboard. For example,COP4338$ sort < myshell.c
COP4338$ sort < myshell.c > 1
COP4338$ sort > 1 < myshell.c
The second and third commands are the same: the sort program reads the file named myshell.c as standard input, sorts it, and then writes to file named 1. - | – Pass the standard output of one command to another for further processing. For example,COP4338$ ls | sort
COP4338$ sort < myshell.c | grep main | cat > output


0 comments