A lightweight, POSIX-compliant command-line shell written in C, featuring advanced parsing, redirections, wildcard expansion, and more.
MiniShell is a custom command-line interpreter designed to mimic the behavior of popular shells (bash, zsh) while introducing robust internal mechanisms such as garbage-collected memory management, detailed debug output, and a modular architecture for easy extension.
- Tokenization & AST Construction: Supports quotes (
',"), command substitution$(cmd), and logical operators (&&,||,|). - Wildcard Expansion: Implements
*and?expsansion within arguments, searching directories recursively.
- Input/Output Redirections:
<,>,>>,<>. - Here-Document (
<<): Inline multi-line input with proper variable expansion support.
cd,export,unset,env,pwd,echo,exitwith POSIX-compatible flags and error handling.
- Dynamic Hashmap: Efficient and fast name-value storage for environment variables, automatically resizing.
- Persistent State: Updates
SHLVL,PWD, andOLDPWDseamlessly.
- Context-aware signal setup for prompt, heredoc, and child processes to ensure a smooth user experience.
- Custom GC: Tracks allocations and automatically frees unused memory at end-of-execution or on errors.
- Prevents leaks and dangling pointers, even in complex pipelines.
- Toggleable debug levels to inspect token lists, AST nodes, and command execution states for rapid development and troubleshooting.
git clone https://github.com/yourusername/minishell.git
cd minishell
make-
Debugging: Set
DEBUGindebug.hto desired level (0–13). -
Shell Name: Customize the shell’s displayed name by editing the
MINISHELL_NAMEmacro inheader.h. -
Prompt: Define a custom prompt format using the
PROMPTmacro inminishell.h. -
Welcome Prompt: Customize the welcome message displayed at shell startup by modifying the
MINISHELL_WELCOME_STARTandMINISHELL_WELCOME_ENDmacros inminishell.h. -
Builtin Command Names: Rename built-in commands by modifying the
BUILTIN_<CMD>_NAMEmacros inbuiltins.h. -
Signal Display: Enable or disable signal reporting by setting
MINISHELL_SHOW_SIGNALSinminishell.h(0 disables, 1 enables). -
Core Dump on Signal: Control core dump message via the
SIGNAL_CORE_DUMP_MESSAGEmacro inminishell_signal.h.
Note: After adjusting any configuration macros in headers run
make clean && maketo recompile and apply your changes or directly runmake CONFIGURATION=-D<DEFINE>=<VALUE>.
Launch the shell interactively:
./minishellRun a script:
./minishell script.shExecute single command:
./minishell -c "echo Hello World"Distributed under the MIT License. See LICENSE for details.
