A comprehensive collection of Bash scripts designed to teach shell scripting from beginner to advanced levels. This repository contains practical examples, real-world automation scripts, and best practices for Bash programming.
π° 01-Basics/
12 fundamental scripts covering essential Bash concepts:
- Basic syntax and structure
- Variables and user input
- Control flow (if-else, case, loops)
- Functions and arrays
- File operations and math
- Command-line arguments
Perfect for: Complete beginners, programming students, quick reference
π 02-Advanced/
16 advanced scripts demonstrating real-world applications:
- System administration and monitoring
- File operations and network tools
- Database backup and automation
- Interactive user interfaces
- Data processing and formatting
- Algorithm implementations
Perfect for: System administrators, DevOps engineers, intermediate scripters
01-Basics/ β Complete all 12 scripts in order
β
02-Advanced/ β Start with system monitoring scripts (01, 03, 04)
β
02-Advanced/ β File operations (05, 06, 09)
β
02-Advanced/ β User interfaces (12, 13, 14)
01-Basics/ β Quick review of fundamentals
β
02-Advanced/ β Focus on automation (01, 02, 10, 11, 16)
β
02-Advanced/ β Network and monitoring tools (07, 08)
β
02-Advanced/ β Algorithm challenges (02-1, 15)
| Category | Basic Scripts | Advanced Scripts | Total |
|---|---|---|---|
| Control Flow | if-else, case, loops | Interactive menus | 6 |
| System Admin | File operations | Log rotation, health checks, monitoring | 8 |
| Data Processing | Variables, arrays, math | Table formatting, algorithms | 7 |
| Automation | Functions, arguments | Backup, database, expect | 5 |
| Network | - | Ping sweep, web status | 2 |
| Total | 12 | 16 | 28 |
- Unix-like operating system (Linux, macOS, WSL on Windows)
- Bash shell (version 4.0+)
- Text editor (vim, nano, VS Code, etc.)
- Basic command line knowledge
# Package installations (Ubuntu/Debian)
sudo apt-get install rsync curl mysql-client expect
# Package installations (CentOS/RHEL)
sudo yum install rsync curl mysql expect
# Package installations (macOS with Homebrew)
brew install rsync curl mysql-client expect-
Clone the repository:
git clone <repository-url> cd bash
-
Make scripts executable:
chmod +x 01-Basics/*.sh chmod +x 02-Advanced/*.sh
-
Start with basics:
cd 01-Basics ./01_hello_world.sh -
Progress to advanced:
cd ../02-Advanced ./04_system_health_check.sh
| Script | Concept | Use Case |
|---|---|---|
01_hello_world.sh |
Basic structure | Your first script |
02_variables.sh |
Variable usage | Data storage |
03_user_input.sh |
Interactive input | User interaction |
04_if_else.sh |
Conditional logic | Decision making |
05_case_statement.sh |
Multi-way branching | Menu systems |
06_for_loop.sh |
Iteration | Repetitive tasks |
07_while_loop.sh |
Conditional loops | Dynamic iteration |
08_functions.sh |
Code organization | Reusable code |
09_arrays.sh |
Data structures | Multiple values |
10_file_operations.sh |
File I/O | File manipulation |
11_math_operations.sh |
Arithmetic | Calculations |
12_script_arguments.sh |
Parameters | Command-line args |
| Category | Scripts | Description |
|---|---|---|
| System Admin | 01_log_rotation.sh03_process_monitor.sh04_system_health_check.sh09_disk_usage_report.sh |
Log management, process monitoring, system status reporting |
| File Operations | 02_backup_script.sh05_bulk_rename_files.sh06_find_large_files.sh10_mysql_backup.sh |
Backup solutions, bulk operations, file discovery |
| Network Tools | 07_network_ping_sweep.sh08_web_status_checker.sh |
Network diagnostics, web monitoring |
| User Interface | 12_interactive_menu.sh13_simple_table_format.sh14_complex_table_format.sh |
Menu systems, data presentation |
| Algorithms | 02-longest-asc-subarray.sh15_min_nearest_zero.sh |
Array processing, mathematical operations |
| Automation | 11_github_repo_cloner.sh16_expect_demo.sh |
Development tools, interactive automation |
- β Understand Bash syntax and structure
- β Work with variables and user input
- β Implement control flow and loops
- β Create and use functions
- β Handle arrays and file operations
- β Process command-line arguments
- β Automate system administration tasks
- β Monitor system health and processes
- β Create professional user interfaces
- β Implement backup and recovery solutions
- β Build network diagnostic tools
- β Process complex data structures
- β Apply advanced automation techniques
- Consistent shebang usage:
#!/bin/bash - Error handling: Safe file operations
- Input validation: Secure user input processing
- Resource management: Efficient system resource usage
- Safe file operations: Proper quoting and path handling
- Input sanitization: Preventing injection attacks
- Permission awareness: Understanding security contexts
- Credential management: Secure handling of sensitive data
- Efficient algorithms: Optimized data processing
- Resource conservation: Memory and CPU efficient scripts
- Parallel processing: Background job management
- Scalable solutions: Scripts that handle varying data sizes
- Test First: Run scripts in safe environments
- Read Code: Understand what scripts do before execution
- Backup Data: Protect important files before running file operations
- Check Permissions: Ensure appropriate access levels
- Validate Inputs: Never trust user input without validation
- Monitor Resources: Watch system impact during execution
This repository welcomes contributions! Areas for improvement:
- Additional algorithm implementations
- Platform-specific optimizations
- Enhanced error handling
- Performance improvements
- Documentation updates
- Bash Manual
- ShellCheck - Script analysis tool
- Advanced Bash Scripting Guide
- Debugging: Use
bash -x script.shfor execution tracing - Validation: Use ShellCheck for code quality
- Testing: Create test cases for your scripts
- Documentation: Comment your code thoroughly
This project is licensed under the MIT License - see the LICENSE file for details.
- Complete the basics: Master all scripts in
01-Basics/ - Practice daily: Incorporate scripts into your workflow
- Modify and experiment: Adapt scripts to your needs
- Build complex solutions: Combine multiple concepts
- Share knowledge: Teach others and contribute back
Happy Scripting! π
Remember: The best way to learn Bash is by doing. Start with the basics, experiment with modifications, and gradually work your way up to the advanced scripts. Each script builds upon previous concepts, creating a comprehensive learning experience.