A lightweight, modular Unix shell implementation written in C that supports basic command execution, built-in commands, and optional readline support for enhanced user experience.
- Command Execution: Execute external programs and system commands
- Built-in Commands: Support for
cd
,exit
, and other internal commands - Input Parsing: Parse command-line input with argument handling
- Modular Design: Clean separation of concerns across multiple modules
- Readline Support: Enhanced input with history and line editing (optional)
- History Management: Command history functionality when readline is available
my_shell/
├── Makefile # Build configuration
├── main.c # Entry point and main loop
├── parser.c / parser.h # Input parsing, redirection, pipes
├── builtins.c / builtins.h # Built-in commands (cd, exit, etc.)
├── executor.c / executor.h # Process execution and pipeline handling
├── prompt.c / prompt.h # User prompt and readline integration
├── history.c / history.h # Command history management
└── README.md # This file
- GCC compiler
- Make utility
- libreadline-dev (optional, for enhanced input features)
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install build-essential libreadline-dev
macOS:
# Install Xcode command line tools
xcode-select --install
# Install readline via Homebrew
brew install readline
- Clone or download the project files
- Navigate to the project directory
- Compile the shell:
make
To clean build artifacts:
make clean
./myshell
-
exit: Quit the shell
exit
-
cd: Change directory
cd /path/to/directory cd .. cd ~
Execute any system command available in your PATH:
ls -la
ps aux
grep "pattern" file.txt
cat file.txt
$ ./myshell
myshell> pwd
/home/user/project/myshell
myshell> ls
Makefile README.md builtins.c builtins.h executor.c executor.h history.c history.h main.c myshell parser.c parser.h prompt.c prompt.h
myshell> cd ..
myshell> pwd
/home/user/project
myshell> exit
$
- Add the command logic to
builtins.c
- Add the function declaration to
builtins.h
- Update the main loop in
main.c
to handle the new command
The modular design makes it easy to extend:
- Parser: Modify
parser.c
to support new syntax features - Executor: Update
executor.c
to handle new execution modes - Built-ins: Add new commands in
builtins.c
- The project automatically detects readline availability
- If readline is not available, basic functionality continues to work
- Use
make install-readline
for installation instructions
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is for educational purposes. Feel free to modify and distribute.
Readline errors during compilation:
- Install libreadline-dev package
- Or modify Makefile to disable readline support
Permission denied errors:
- Ensure the executable has proper permissions:
chmod +x myshell
Command not found:
- Check that external commands are in your PATH
- Use absolute paths for custom executables
- Pipe support (
|
) - Input/Output redirection (
>
,<
,>>
) - Background process execution (
&
) - Environment variable support
- Tab completion
- Signal handling (Ctrl+C, Ctrl+Z)
- Job control
- Scripting support