Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.26 KB

File metadata and controls

44 lines (33 loc) · 1.26 KB

Unix Shell in C

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.

Technical Highlights

  • Process model: fork/execvp/waitpid for child process lifecycle management
  • I/O redirection: dup2-based fd swapping for stdout/stderr, supporting both overwrite and append modes
  • PATH resolution: manual $PATH traversal with stat to 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, exit implemented natively without spawning child processes

Build

make

Requires GCC. Compiled with -Wall -Wextra -g.

Usage

./shell
$ echo "hello world"
hello world
$ ls 2> errors.txt
$ cat file.txt >> log.txt
$ exit

Redirection

Operator Effect
> / 1> Redirect stdout (overwrite)
2> Redirect stderr (overwrite)
>> / 1>> Redirect stdout (append)
2>> Redirect stderr (append)