A compact, educational Unix-style shell written in C with common features useful for learning and small scripting tasks.
Highlights
- Builtins:
cd,exit,history,exportπ§ - Pipelines:
|support for chaining commands π - Redirection: input
<, output>and append>>π - Background execution: run jobs with
&βοΈ - Variable expansion:
$VARis expanded using environment variables π‘ - Script execution: run shell scripts by passing a filename
- Signal handling: graceful
Ctrl+Chandling (SIGINT) π‘οΈ
Why this project?
- Great for learning process control,
fork(),execve()/execvp(), pipes, and basic shell features. - Minimal, contained implementation β useful as a teaching aid or starting point for enhancements.
Build
On Linux / WSL / macOS (recommended):
gcc -o myshell My_Shell.cOn Windows (use WSL, MinGW, or MSYS2):
- With MinGW (example):
gcc -o myshell.exe My_Shell.cNotes: Some platform differences (signals, /dev/null, path behavior) may exist on native Windows β WSL provides the closest behavior to Unix.
Run
Interactive shell:
./myshell # or myshell.exe on WindowsRun a script file:
./myshell myscript.shUsage Examples
- Change directory:
cd /path/to/dir- See command history:
history- Pipeline example:
ls -la | grep ".c" | sort- Redirect output and append:
echo "hello" > out.txt
cat file.txt >> out.txt-
Run in background:
sleep 10 & -
Export environment variable:
export MYVAR=hello echo $MYVAR
Implementation notes (quick)
- Parsing:
strtok()-based splitting on spaces; simple and intentional for clarity. - Redirection: handled by scanning args and
dup2()beforeexecvp(). - Pipelines: splits on
|, usespipe()+ multiplefork()s. - History: in-memory
history[]array (no file persistence).
Limitations & TODO
- Quoting and escaped spaces are not fully supported.
- No command-line editing (no readline support).
- No persistent history file.
- Limited error handling for malformed input.