rush is a lightweight Unix shell written in C that implements core shell functionality including command execution, built-in commands, redirection, and parallel processing.
The goal of this project is to demonstrate process management, system calls, and command parsing in a Unix/Linux environment.
rush is a command-line interpreter that repeatedly:
- Displays a prompt
- Reads user input
- Parses the command
- Executes the command
- Waits for completion
- Repeats until the user exits
Example prompt:
rush>
- Command prompt and execution loop
- Built-in commands:
exit,cd,path - Executable path resolution
- Output redirection (
>) - Parallel command execution (
&) - Robust error handling
- Flexible whitespace parsing
.
├── makefile
├── rush.c
└── README.md
- Linux environment
- GCC
makeThis produces the executable:
./rush
./rushYou will see:
rush>
Type commands just like a normal Unix shell.
External commands are executed using:
fork()— create child processexecv()— run the programwait()/waitpid()— wait for completion
The shell searches for executables using directories defined in the path list.
Default path:
/bin
Exits the shell.
rush> exitRules:
- No arguments allowed.
Changes the current working directory.
rush> cd /tmpRules:
- Must receive exactly one argument.
Sets the executable search path.
rush> path /bin /usr/binClear the path:
rush> pathRedirect command output using >:
rush> ls -la > files.txtBehavior:
- Output file is created if it does not exist
- Existing files are overwritten
- Errors during file creation are reported
Use & to run commands simultaneously:
rush> sleep 1 & ls & echo doneThe shell waits until all commands finish before showing the next prompt.
All errors print a single message to stderr:
An error has occurred
The shell continues running after most errors.
rush> path /bin
rush> ls
rush> cd /tmp
rush> ls > output.txt
rush> sleep 1 & echo hello & ls
rush> exit