This project features a C program that implements a Unix-like shell, supporting I/O redirection and piping.
To compile the program, use the provided Makefile:
makeTo start the shell (assuming you are in the same directory):
./myshThis will bring you to a prompt that looks like this:
$You can now use this shell similarly to the default UNIX shell. Below are some demonstrations of the I/O redirection and piping support. These operations can be combined, as shown in the piping examples.
To read input from a file called input.txt:
$ cat < input.txt Note: This is not a typical use of the cat command but is done for demonstration purposes.
To write the output of ls -al to a file called output.txt and to overwrite everything previously written in output.txt:
$ ls -al > output.txtHowever, to append to output.txt:
$ ls >> output.txtThis shell supports multiple piping, allowing the output of one program to be passed as input to another. This is useful in various scenarios.
For example, to read a file's content, count the number of lines, and store the count in another file:
$ cat output.txt | wc -l > line_countTo read a file's contents, find a specific keyword (say mysh), count the number of lines where the keyword appears, and store the output in a new file:
$ cat output.txt | grep -i mysh | wc -l > grepped_line_countTo test multiple piping support, you can chain several cat commands:
$ cat output.txt | grep -i mysh | wc -l | cat | cat | cat | cat > grepped_line_countTo exit the shell, type the exit command or press CTRL + D.