MyMiniShell is a small Linux shell written in C as a learning project. Its goal is to build an understanding of input handling, parsing, built-in commands, processes, system calls, pipes, and redirection one stage at a time.
- Build the REPL loop: prompt, read, repeat, and
exit. - Parse input into a command and arguments.
- Add built-in commands such as
help,pwd, andcd. - Run external programs using Linux process APIs.
- Add pipes.
- Add input and output redirection.
Each stage should be understood and tested before moving to the next one.
The first version can:
- display the
minishell>prompt; - read one line safely with
fgets; - remove the trailing newline;
- exit when the user enters
exit; - stop cleanly when it reaches end-of-file (
Ctrl+D).
It does not execute external commands yet. That is intentional.
MyMiniShell currently supports:
- Interactive REPL prompt
- Command tokenization
- Built-in commands:
helpexitpwdcd
- External command execution using
fork(),execvp(), andwaitpid() - Child-process exit status handling
- Output redirection:
>— create or truncate a file>>— append to a file
- Input redirection with
< - Combined input and output redirection
- Pipelines containing multiple external commands
- Automated tests for tokenization, external commands, redirection, and pipelines
./minishellminishell> pwd
/home/user/MyMiniShell
minishell> echo hello
hello
minishell> echo hello > output.txt
minishell> cat output.txt
hello
minishell> echo second >> output.txt
minishell> sort < unsorted.txt > sorted.txt
minishell> ls | grep test | wc -l
minishell> exit
MyMiniShell is a learning project and is not intended to replace a production shell.
The current parser:
- Requires spaces around operators such as
|,<,>, and>> - Does not yet understand single or double quotes
- Does not support escape sequences
- Does not support environment-variable expansion such as
$HOME - Does not support wildcard expansion such as
*.c - Does not yet combine redirection with pipelines
- Supports built-ins only outside pipelines
- Does not include job control or background execution with
&
Build and run all tests with:
make clean testThe test suite currently covers:
- Tokenization
- External command execution and exit statuses
- Input, output, append, and combined redirection
- Single and multiple-command pipelines
Some negative tests intentionally print error messages while confirming that invalid commands return the expected status.
MyMiniShell/
├── include/ # Header files when the project grows
├── src/
│ └── main.c
├── tests/ # Tests added with later stages
├── .gitignore
├── Makefile
└── README.md
On Ubuntu, install the compiler tools once:
sudo apt update
sudo apt install build-essential gitThen build and run:
make
./minishellOr use:
make runRemove the compiled program with:
make cleanminishell> hello
minishell> exit
hello is only read at this stage; it is not executed. The second line exits
the shell.