Skip to content

This repository contains a collection of Bash scripting code snippets to help you learn and improve your scripting skills. It covers topics from basic concepts like variables, arrays, and comments to more advanced topics like conditional statements, loops, and string operations.

Notifications You must be signed in to change notification settings

sandeeep-prajapati/bash_Scripting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bash Scripting Code Snippets

Welcome to the Bash Scripting Code Snippets repository! This repository contains a collection of Bash scripting code examples that cover various fundamental concepts, designed to help beginners and seasoned developers alike learn and improve their skills in Bash scripting.

Table of Contents

  1. Introduction
  2. Hello World
  3. Comments
  4. Variables
  5. Shell Type
  6. First Basic Script
  7. What is a Shebang?
  8. Sending Output to Terminal
  9. Comments
  10. Variables
  11. Constant Variables
  12. Arrays
  13. Array Key-Value Pairs
  14. String Operations
  15. Taking Input
  16. Arithmetic Operations
  17. Conditional Statements
  18. Else If
  19. Case Statements
  20. Logical Operators
  21. Logical Operators
  22. For Loop
  23. Until Loop
  24. Infinite Loop
  25. While Loop
  26. Special While Loop
  27. Functions
  28. Functions with Arguments
  29. Arguments in Scripts
  30. Shifting Arguments

Code Snippets

1. Introduction

File: 01_introduction.sh
A brief introduction to Bash scripting, explaining what it is and its common use cases.

2. Hello World

File: 02_hello_world.sh
Your first Bash script that prints "Hello, World!" to the terminal.

3. Comments

File: 03_comments.sh
How to write comments in Bash scripts for better code documentation and understanding.

4. Variables

File: 04_variables.sh
An introduction to using variables in Bash, including how to declare, assign, and use them.

5. Shell Type

File: 05_sell_type.sh
Explains different types of shells available in Unix/Linux systems and how to find out the current shell type.

6. First Basic Script

File: 06_first_Basic_script.sh
Guide to creating and executing your first basic Bash script.

7. What is a Shebang?

File: 07_what_is_sherang.sh
An explanation of the shebang (#!) line at the beginning of scripts and its purpose.

8. Sending Output to Terminal

File: 08_sending_output_to_terminal.sh
How to send output from a script to the terminal using various methods.

9. Comments

File: 09_comments.sh
(duplicate entry) Similar to the third snippet, focuses on using comments in scripts.

10. Variables

File: 10_variables.sh
(duplicate entry) Similar to the fourth snippet, covers using variables in Bash.

11. Constant Variables

File: 11_constant_variable.sh
How to declare and use constant variables that cannot be changed once set.

12. Arrays

File: 12_array.sh
Introduction to arrays in Bash, including declaring, initializing, and accessing array elements.

13. Array Key-Value Pairs

File: 13_array_key_value.sh
Using associative arrays (key-value pairs) in Bash scripts.

14. String Operations

File: 14_String_opertion.sh
Different string operations in Bash, such as concatenation, comparison, and finding substrings.

15. Taking Input

File: 15_taking_input.sh
Methods to take input from the user in Bash scripts.

16. Arithmetic Operations

File: 16_arithmetic_operation.sh
Performing arithmetic operations like addition, subtraction, multiplication, and division in Bash.

17. Conditional Statements

File: 17_conditional_statement.sh
Using if statements to execute code based on conditions.

18. Else If

File: 18_else_if.sh
Using else if statements to handle multiple conditions in Bash.

19. Case Statements

File: 19_case.sh
Using case statements as an alternative to multiple if-else conditions.

20. Logical Operators

File: 20_logical_operators.sh
Using logical operators (&&, ||, !) in Bash scripting to combine conditions.

21. Logical Operators

File: 21_Logical_operators.sh
(duplicate entry) Similar to the 20th snippet, focuses on logical operators.

22. For Loop

File: 22_loop.sh
How to use for loops in Bash scripting for iterating over a sequence of items.

23. Until Loop

File: 23_until_loop.sh
How to use until loops in Bash scripting to execute code as long as a condition is false.

24. Infinite Loop

File: 24_infinit_loop.sh
How to create and use infinite loops in Bash scripting.

25. While Loop

File: 25_while_loop.sh
How to use while loops in Bash scripting to execute code while a condition is true.

26. Special While Loop

File: 26_epecial_while_loop.sh
Using special cases of while loops for more complex looping scenarios.

27. Functions

File: 27_function.sh
Introduction to creating and using functions in Bash scripting.

28. Functions with Arguments

File: 28_argu_function.sh
How to pass arguments to functions in Bash and use them effectively.

29. Arguments in Scripts

File: 29_arguments_script.sh
Handling and using command-line arguments passed to a script.

30. Shifting Arguments

File: 30_shifting_argumemts.sh
Using the shift command to manage multiple arguments in a script.

How to Use

  1. Clone the repository to your local machine using:

    git clone <repository-url>
  2. Navigate to the repository directory:

    cd bash-scripting-snippets
  3. Make sure the scripts are executable:

    chmod +x *.sh
  4. Run any script using the following command:

    ./<script_name>.sh

Prerequisites

  • A Unix/Linux-based system (or Windows with a Bash emulator like Git Bash)
  • Basic knowledge of the terminal and command line

Contributing

If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request. Contributions are welcome!

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

This repository contains a collection of Bash scripting code snippets to help you learn and improve your scripting skills. It covers topics from basic concepts like variables, arrays, and comments to more advanced topics like conditional statements, loops, and string operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages