minishell

POSIX-compliant shell in C · 2025

“The shell is a window into the operating system's soul.”

Unix shell from scratch — process management, file descriptors, pipes, I/O redirection, environment expansion, signal handling.

Standard
POSIX
Primitives
fork/exec
Signals
sigaction

Problem: Understanding how a Unix shell works requires deep knowledge of operating system fundamentals, and 42's minishell project forbids leaning on any of them from a library — no shell libraries, only raw libc and system calls. That means quoting, expansion, redirection, and pipelines all have to be built from first principles, and getting any one of them subtly wrong (a heredoc that doesn't respect quoted delimiters, an unset that leaves a stale env var visible to a child) is invisible until it breaks a specific command.

Solution: A POSIX-compliant shell in C that replicates bash's core behavior. A hand-written lexer and recursive-descent parser turn raw input into a token stream that respects single/double-quote semantics and here-doc boundaries, then an execution engine walks that structure using genuine Unix system calls — no system(), no shortcuts.

Technical Approach: Three systems-programming concepts carry the implementation. Process management via fork/execve with correct PATH resolution and exit-status propagation back through pipelines. File descriptor manipulation through dup2() for multi-stage pipes and I/O redirection (<, >, >>, here-docs), including keeping descriptors from leaking into children that shouldn't inherit them. And signal handling with sigaction() so SIGINT/SIGQUIT behave differently at the prompt versus inside a running child, without ever leaving a zombie process behind.

Results & Learnings: Building minishell transformed my understanding of Unix architecture — shells are orchestrators of the OS, not autonomous entities, and the same process/IPC discipline is exactly what shows up later in gRPC-bridged services or a multi-threaded render loop. Hands-on exploration of process management, file descriptors, and IPC deepened my appreciation for why low-level programming discipline matters.

Language
C
Focus
Unix internals · syscalls