Name: Manya Jain
msh is a custom, interactive command-line interpreter (shell) written in C. It aims to replicate the core behavior of standard shells like Bash or Zsh, while remaining intentionally minimal. Despite its simplicity, it supports built-in commands, external program execution, input/output redirection, background processing, and persistent command history.
The project is organized to ensure modularity and clean compilation.
├── makefile # Build automation configuration
├── shell.h # Main header file (structs, global vars, prototypes)
├── msh # Final executable (generated after make)
├── README.md # Documentation
├── src/ # Source code directory
│ ├── main.c
│ ├── prompt.c
│ ├── builtins.c
│ ├── history.c
│ ├── process.c
│ ├── signal_handlers.c
│ └── utils.c
└── build/ # Object files (.o) directory (generated during build)
├── main.o
...
This project uses a Makefile to do the heavy lifting, so you don’t have to. Just a few simple commands :
Build the project and create the msh executable:
make
Or if you like being extra :
make allOnce compiled, execute the shell:
./mshTo remove the msh executable and the build/ directory (and object files):
make clean-
Shell Prompt
Displays<user@system:path>with colored formatting and support for~as a relative home directory path. -
Built-in Commands
pwd: Display the current working directory.cd: Change the current directory (supports..,~, and-).help: Show the help menu.echo: Print arguments to standard output.exit: Exit the shell cleanly.history: Display the last 20 executed commands.
-
Input/Output Redirection
- Output redirection:
command > output.txt - Input redirection:
command < input.txt
- Output redirection:
-
External Commands
Executes standard system programs such asls,vim, andgrep. -
Signal Handling
Ctrl+D: Exits the shell.Ctrl+C: Terminates the foreground process without exiting the shell.
-
Background Execution
Supports background processes using&(e.g.,docker-compose build &). -
Command History Persistence
Command history is stored in~/.msh_historyand restored on subsequent sessions.