Simple command-line shell emulator written in C.
It replicates the basic functionality of a UNIX shell — including executing external programs, handling built-in commands (cd, pwd, exit), managing I/O redirection, and supporting multiple pipes in a single command line.
The goal of this project is to gain an understanding of process control and system call interfaces in Linux, while maintaining modular and readable C code.
| Command | Description |
|---|---|
cd [dir] |
Changes the current working directory. If no argument is provided, it defaults to $HOME |
pwd |
Prints the current working directory |
exit [status] |
Exits the shell (optionally accepts an exit code) |
- Executes any valid executable in your
$PATH. - Handles invalid commands gracefully with error messages.
| Operator | Description | Example |
|---|---|---|
> |
Redirects standard output to a file (creates/truncates file) | ls > out.txt |
< |
Redirects standard input from a file | sort < data.txt |
Supports multiple pipes, allowing chained commands:
cat input.txt | grep error | sort | uniqSupports $? to access the exit status of the last executed command:
echo $?- Detects missing filenames or syntax errors in redirections
- Detects empty pipe commands (e.g.,
| lsorls | | grep) and ignores them (ls || grepbecomesls | grep) - Prints descriptive errors using strerror(errno)
- Can exit out of running commands using Ctrl+C
- Interactive mode: Standard command-line interface ($ prompt)
- Batch mode: Execute commands from a file:
./shell commands.txt- To compile the shell
make- Start the shell in interactive mode
./shell- To clean the directory
make clean| Command | Description |
|---|---|
| Background jobs (&) | Allow commands to run asynchronously in the background |
| Command history | Support !!, !n, and arrow-key navigation |
| Environment variables | Expand $PATH, $HOME, etc., and support export |
| Append redirection (>>) | Add output appending functionality |
| Logical operators | Allow sequential and conditional command execution |