MShell stands for Modularized Shell. It helps you write large yet well-maintainable shell scripts.
MShell is a framework designed to bring modularity, structure, and enterprise-grade features to shell scripting. It transforms traditional linear shell scripts into organized, maintainable applications with proper error handling, logging, and module systems.
MShell follows a clean architecture with distinct layers:
- Launcher: Entry point that initializes the environment
- Module System: Reusable components with
importModulesyntax - Job Scheduler: Manages execution lifecycle with logging and monitoring
- Handlers: Business logic containers following the handler pattern
- Configuration: Profile-based environment management
MacOS & Linux:
git clone https://github.com/maoshuai/mshell.git
echo 'MSHELL_PROFILE=dev' > ~/.mshellrc# Run a simple handler
./shell/launcher.sh sample/4_use_module.sh "hello world"
# Run any shell script (backward compatible)
./shell/launcher.sh sample/1_native_shell.shImport reusable modules anywhere in your scripts:
importModule 'log'
importModule 'util'
handler_main(){
logInfo "Processing arguments: $@"
util_assertArgumentNotEmpty "$1" "first argument"
}All business logic should be implemented as handlers in shell/handler/:
- Define a
handler_main()function as the entry point - Import modules as needed
- Return appropriate exit codes for job status
Each handler execution is treated as a job with full lifecycle management:
- Initialization: Set up logging, generate job ID, acquire locks
- Execution: Run your
handler_main()function - Monitoring: Track execution time, parameters, and system info
- Cleanup: Release resources and output execution summary
MShell comes with several built-in modules:
log: Structured logging with multiple levels (info, warn, error, echo)util: Utility functions (util_assertArgumentNotEmpty,util_isFileEmpty)job: Job scheduling and lifecycle managementprofile: Configuration profile managementlock: File-based locking for concurrent execution safetygit: Git repository information integrationcache: Simple caching mechanisms
- Complex Automation Scripts: When your shell scripts grow beyond simple sequences
- DevOps Tooling: Reliable, logged, and monitored operational scripts
- CI/CD Pipelines: Structured build and deployment scripts
- System Administration: Maintainable and debuggable admin scripts
mvn clean package- Create a new file in
shell/handler/ - Import required modules with
importModule - Implement your
handler_main()function - Execute via
./shell/launcher.sh your_handler_name
- Create
.modulefiles inshell/module/ - Define functions and variables
- Import in handlers using
importModule 'your_module_name'
Distributed under the Apache License 2.0. See LICENSE for more information.
- Fork it (https://github.com/maoshuai/mshell/fork)
- Create your feature branch (
git checkout -b feature/fooBar) - Commit your changes (
git commit -am 'Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Create a new Pull Request
Maoshuai – GitHub – imshuai67@gmail.com
AI Assistant (maobot2026) – GitHub – maobot2026@users.noreply.github.com
This project documentation and recent contributions were co-developed by an AI assistant in collaboration with Maoshuai.
Write better shell scripts with MShell's modular approach!
