Custom Unix Shell
Tru Bui
A custom Unix shell written in C/C++. Supports running programs,
redirection, pipes, background jobs, line editor, wildcard expansion, and path completion. Built using Flex and Bison.
Your browser does not support the video tag.
Key Features
Lex/Yacc-based parser supporting complex command grammars
Execution engine using fork(), execvp(), and waitpid()
Full support for I/O redirection: >, >>, <, 2>, >&, >>&
Pipe operator
Background job execution (&) and process management
Signal handling: Ctrl-C behavior, SIGCHLD zombie cleanup
Built-in commands: cd, exit, setenv, unsetenv, printenv, source
Subshells
Environment variable expansion
Tilde expansion & wildcarding (* and ? with regex)
Custom line editor (arrow keys, backspace, delete, home/end)
Command history with up/down arrows
Implementation Details
The project is split into several core components:
Lexer (Flex): tokenizes commands, handles quotes, escapes, subshell extraction
Parser (Bison): builds a full AST of Command and SimpleCommand objects
Executor: performs process creation, piping, redirection, job control
Signal subsystem: manages Ctrl-C and zombie processes safely
Line editor: implements raw-terminal input, cursor movement, dynamic insertion
Wildcard engine: converts shell wildcards to regex using regcomp
Subshell mechanism: uses two pipes + yy_unput() to inject subshell output into lexer
Contact me to see source code!