Skip to content

Latest commit

 

History

History
137 lines (104 loc) · 4.85 KB

File metadata and controls

137 lines (104 loc) · 4.85 KB

Bash Shell Scripting Collection

Bash Logo License Scripts

🚀 About This Repository

A comprehensive collection of Bash scripts demonstrating fundamental to advanced shell scripting concepts. This repository serves as both a learning resource and a practical reference for Linux/Unix shell scripting techniques. It includes both educational scripts covering core concepts and real-world practical projects for system administration tasks.

📋 Contents

This repository contains scripts covering:

  • Basics: Basic syntax, comments, variables, and constants
  • Data Structures: Arrays, key-value pairs, string operations
  • Control Flow: If-else statements, case statements, logical operators
  • Loops: For, while, until loops with various implementations
  • Functions: Creation and usage with arguments
  • File Operations: Reading from files, CSV processing
  • System Management: Connectivity checks, file existence checks
  • Debugging: Logging, error handling techniques
  • Advanced Concepts: Background processing, redirection
  • Real-world Projects: File archiving, system monitoring, user management

🗂️ Script Categories

Fundamentals

  • 01_basic.sh - Hello world example
  • 02_comments.sh - Single and multi-line comments
  • 03_var.sh - Variable declaration and usage
  • 04_constant_var.sh - Constants and readonly variables

Data Handling

  • 05_array.sh - Array operations
  • 06_keyvalues.sh - Key-value pair handling
  • 07_string_ops.sh - String manipulation
  • 08_user_int.sh - User input handling
  • 09_arithmetic.sh - Mathematical operations

Control Structures

  • 10_if_else.sh - Basic conditionals
  • 11_elif.sh - Multiple condition handling
  • 12_choice.sh - Case statements
  • 13_logical.sh - AND/OR operators
  • 14_ternary_ops.sh - Ternary operations

Loops

  • 15_loops.sh - For loop basics
  • 16_for_with_file.sh - File processing with loops
  • 17_for-with_array.sh - Array iteration
  • 18_while_loop.sh - While loop implementation
  • 19_until_loop.sh - Until loop example
  • 20_infinite_loop.sh - Infinite loop demonstrations
  • 21_while_with_file.sh - File processing with while
  • 23_while_with_csv.sh - CSV processing

Functions & Arguments

  • 24_function.sh - Function definition and calling
  • 25_func_with_args.sh - Function arguments
  • 26-args.sh - Script arguments
  • 27_shift_args.sh - Shift argument technique

System Operations

  • 28_break.sh - Loop breaking
  • 29_connectivity_check.sh - Network connectivity testing
  • 30_file_exists_or_not.sh - File existence verification
  • 31_random_dice.sh - Random number generation
  • 32_root_user.sh - User privilege checking
  • 33_redirect.sh - Output redirection
  • 34_dev_null.sh - Discarding output
  • 35_name_retrieve.sh - Script name retrieval

Advanced Techniques

  • 36_logger.sh - System logging
  • 37_debug.sh - Script debugging
  • 38_debugging.sh - Error handling with set -e
  • 39_running_background.sh - Background process execution

Practical Projects

  • archieve_files.sh - Automatically archives large files (20MB+) to save disk space
  • file_sys_status.sh - Monitors filesystem space and sends email alerts when space is low
  • ram_monitoring.sh - Checks available RAM and provides alerts when memory is running low
  • user_make.sh - Creates new system users with auto-generated passwords and proper permissions

🛠️ Usage

Each script is standalone and can be executed directly after making it executable:

# Make a script executable
chmod +x script_name.sh

# Execute a script
./script_name.sh

📚 Learning Path

This repository is organized in a progressive learning path:

  1. Start with basics (01-09)
  2. Move to control structures (10-14)
  3. Learn loops (15-23)
  4. Understand functions and arguments (24-27)
  5. Explore system operations (28-35)
  6. Master advanced techniques (36-39)
  7. Apply knowledge with real-world projects

🔍 Requirements

  • Bash shell (version 4.0 or higher recommended)
  • Linux/Unix environment or Windows with WSL
  • Root/sudo access (for some system administration scripts)

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Rohan


This repository is maintained and updated regularly. Last update: May 2025