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.
- Introduction
- Hello World
- Comments
- Variables
- Shell Type
- First Basic Script
- What is a Shebang?
- Sending Output to Terminal
- Comments
- Variables
- Constant Variables
- Arrays
- Array Key-Value Pairs
- String Operations
- Taking Input
- Arithmetic Operations
- Conditional Statements
- Else If
- Case Statements
- Logical Operators
- Logical Operators
- For Loop
- Until Loop
- Infinite Loop
- While Loop
- Special While Loop
- Functions
- Functions with Arguments
- Arguments in Scripts
- Shifting Arguments
File: 01_introduction.sh
A brief introduction to Bash scripting, explaining what it is and its common use cases.
File: 02_hello_world.sh
Your first Bash script that prints "Hello, World!" to the terminal.
File: 03_comments.sh
How to write comments in Bash scripts for better code documentation and understanding.
File: 04_variables.sh
An introduction to using variables in Bash, including how to declare, assign, and use them.
File: 05_sell_type.sh
Explains different types of shells available in Unix/Linux systems and how to find out the current shell type.
File: 06_first_Basic_script.sh
Guide to creating and executing your first basic Bash script.
File: 07_what_is_sherang.sh
An explanation of the shebang (#!
) line at the beginning of scripts and its purpose.
File: 08_sending_output_to_terminal.sh
How to send output from a script to the terminal using various methods.
File: 09_comments.sh
(duplicate entry) Similar to the third snippet, focuses on using comments in scripts.
File: 10_variables.sh
(duplicate entry) Similar to the fourth snippet, covers using variables in Bash.
File: 11_constant_variable.sh
How to declare and use constant variables that cannot be changed once set.
File: 12_array.sh
Introduction to arrays in Bash, including declaring, initializing, and accessing array elements.
File: 13_array_key_value.sh
Using associative arrays (key-value pairs) in Bash scripts.
File: 14_String_opertion.sh
Different string operations in Bash, such as concatenation, comparison, and finding substrings.
File: 15_taking_input.sh
Methods to take input from the user in Bash scripts.
File: 16_arithmetic_operation.sh
Performing arithmetic operations like addition, subtraction, multiplication, and division in Bash.
File: 17_conditional_statement.sh
Using if
statements to execute code based on conditions.
File: 18_else_if.sh
Using else if
statements to handle multiple conditions in Bash.
File: 19_case.sh
Using case
statements as an alternative to multiple if-else
conditions.
File: 20_logical_operators.sh
Using logical operators (&&
, ||
, !
) in Bash scripting to combine conditions.
File: 21_Logical_operators.sh
(duplicate entry) Similar to the 20th snippet, focuses on logical operators.
File: 22_loop.sh
How to use for
loops in Bash scripting for iterating over a sequence of items.
File: 23_until_loop.sh
How to use until
loops in Bash scripting to execute code as long as a condition is false.
File: 24_infinit_loop.sh
How to create and use infinite loops in Bash scripting.
File: 25_while_loop.sh
How to use while
loops in Bash scripting to execute code while a condition is true.
File: 26_epecial_while_loop.sh
Using special cases of while loops for more complex looping scenarios.
File: 27_function.sh
Introduction to creating and using functions in Bash scripting.
File: 28_argu_function.sh
How to pass arguments to functions in Bash and use them effectively.
File: 29_arguments_script.sh
Handling and using command-line arguments passed to a script.
File: 30_shifting_argumemts.sh
Using the shift
command to manage multiple arguments in a script.
-
Clone the repository to your local machine using:
git clone <repository-url>
-
Navigate to the repository directory:
cd bash-scripting-snippets
-
Make sure the scripts are executable:
chmod +x *.sh
-
Run any script using the following command:
./<script_name>.sh
- A Unix/Linux-based system (or Windows with a Bash emulator like Git Bash)
- Basic knowledge of the terminal and command line
If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request. Contributions are welcome!
This project is licensed under the MIT License. See the LICENSE
file for more details.