A POSIX-style shell built from scratch in C that supports command execution, built-in commands, PATH resolution, tokenization, and I/O redirection. Designed as an exercise in Unix process management and systems programming.
- Process model:
fork/execvp/waitpidfor child process lifecycle management - I/O redirection:
dup2-based fd swapping forstdout/stderr, supporting both overwrite and append modes - PATH resolution: manual
$PATHtraversal withstatto locate and validate executables - Tokenizer: hand-rolled parser handling single quotes, double quotes, and backslash escaping with correct precedence
- Built-ins:
cd,pwd,echo,type,exitimplemented natively without spawning child processes
makeRequires GCC. Compiled with -Wall -Wextra -g.
./shell$ echo "hello world"
hello world
$ ls 2> errors.txt
$ cat file.txt >> log.txt
$ exit
| Operator | Effect |
|---|---|
> / 1> |
Redirect stdout (overwrite) |
2> |
Redirect stderr (overwrite) |
>> / 1>> |
Redirect stdout (append) |
2>> |
Redirect stderr (append) |