This project implements a simple Unix shell in C that supports built-in commands, command execution with forking, input/output redirection, and pipes. The shell reads user input, parses commands, and executes them accordingly.
- Built-in commands:
help- Displays available commands.exit- Exits the shell.cd <dir>- Changes the current directory.mkdir <dir>- Creates a new directory.!!- Repeats the last executed command.
- Command Execution:
- Runs standard Unix commands using
execvp(). - Supports single commands and multiple arguments.
- Runs standard Unix commands using
- Input/Output Redirection:
- Uses
>to redirect output to a file. - Uses
<to read input from a file.
- Uses
- Piping Support:
- Recognizes the
|operator to pass output between commands.
- Recognizes the
- Special Commands:
ECHO- Prints commands without redirection or pipes.IO- Prints filenames used for input/output redirection.PIPE- Displays pipeline execution steps.
To compile the shell, run:
gcc -o shell shell.cTo start the shell, run:
./shell$ ls
$ whoami
$ date$ help
$ mkdir test_folder
$ cd test_folder
$ !!$ echo "Hello" > output.txt
$ cat < output.txt$ ls | wc -l$ cal feb 2025 > t.txt ECHO # Output: "cal feb 2025"
$ cat < input.txt IO # Output: "LT input.txt"
$ cat shell.c | wc PIPE # Output: "PIPE wc"- The shell does not yet support complex piping with multiple redirections.
- Background process execution (
&) is not implemented.
- Implement signal handling (Ctrl+C to terminate processes cleanly).
- Add support for background processes.
- Improve error handling for invalid commands.
- Developed as part of a Unix shell programming assignment.