A Bash-like Unix shell implemented in Python
PyShell is a lightweight Unix-style shell written in Python that mimics core Bash behavior.
It supports built-in commands, pipelines, redirection, environment variable expansion, command history with persistence, and tab completion using GNU Readline.
This project was built as a systems-level learning exercise, inspired by the Codecrafters Shell Challenge.
- Command parsing with
shlex - Execution of external commands via
subprocess - Built-in command support
- Environment variable expansion (
$VAR,${VAR})
- Pipes (
|) - Input redirection (
<) - Output redirection (
>,>>) - File descriptor redirection (
1>,2>)
- Persistent command history across sessions
HISTFILEenvironment variable support- Built-in
historycommand with:history– show historyhistory -a [file]– append new commandshistory -r [file]– read history from filehistory -w [file]– write history to filehistory -c– clear in-memory history
- Correct incremental append behavior (no duplicates)
- Tab completion for:
- Built-in commands
- Executables in
$PATH - Files and directories
- Command auto-completion display
- Interactive prompt (
$)
| Command | Description |
|---|---|
cd |
Change directory |
pwd |
Print current directory |
echo |
Print arguments |
type |
Identify command type |
history |
Manage command history |
exit |
Exit the shell |
- Linux (tested on Ubuntu)
- Python 3.8+
- GNU Readline
python3 main.py