Welcome back to Day 8 of the #90DaysOfDevOps Challenge! Today, we're diving deep into the basics of Bash Scripting, a powerful tool in every DevOps engineer's toolkit. Whether you're automating tasks or configuring your server environment, shell scripting is essential. Let's break down todayβs tasks and get hands-on with some scriptwriting.
π‘ Task 1: Comments in Bash Scripts
Comments are essential for understanding and maintaining scripts. They are used to add notes, disable certain lines of code, or explain the purpose of the script.
Challenge:
Write a bash script that includes comments explaining what each part of the script does.
!/bin/bash
This is a comment explaining the script's purpose
echo "Welcome to Day 8 of DevOps!"
The script will print a welcome message above
π‘ Task 2: Echo Command
The echo command is used to display messages to the terminal. This is handy for showing information or the result of commands.
Challenge:
Create a bash script that prints a message of your choice.
!/bin/bash
Displaying a message using echo
echo "Learning DevOps is fun!"
π‘ Task 3: Working with Variables
Variables are placeholders used to store data. You can use them in your scripts to store values like strings, integers, or command results.
Challenge:
Create a bash script that declares variables and assigns values to them.
!/bin/bash
Declaring and assigning variables
name="DevOps Ninja"
age=25
echo "My name is $name and I am $age years old."
π‘ Task 4: Using Variables to Perform a Task
Let's get interactive! You can perform operations using variables in bash scripting. Hereβs how you can add two numbers.
Challenge:
Create a bash script that takes two variables as input and prints their sum.
!/bin/bash
Adding two numbers using variables
num1=15
num2=25
sum=$((num1 + num2))
echo "The sum of $num1 and $num2 is $sum."
π‘ Task 5: Utilizing Built-in Variables
Bash has several built-in variables that provide useful information like the script name, the number of arguments passed, and more.
Challenge:
Create a bash script that uses at least three built-in variables to display information.
!/bin/bash
Using built-in variables
echo "Script Name: $0"
echo "Number of arguments passed: $#"
echo "The process ID of this script: $$"
π‘ Task 6: Using Wildcards for Pattern Matching
Wildcards are special characters that help match patterns. They're useful when working with multiple files.
Challenge:
Create a bash script that lists all files with a specific extension in a directory.
!/bin/bash
Listing all .txt files in the current directory
echo "Listing all .txt files in the directory:"
ls *.txt
β
Submission Guidelines:
Complete the tasks in a single bash script.
Document your script with comments explaining each section.
Upload your script to a GitHub repository.
Share your submission with the community!
Conclusion: Bash scripting might seem daunting at first, but with practice, it becomes a valuable tool for automating tasks in your DevOps workflow. As we advance through the #90DaysOfDevOps Challenge, youβll build stronger scripting skills and be ready for more complex automations.
What's Next?
Tomorrow, weβll tackle more advanced scripting concepts, so stay tuned and keep scripting!
Top comments (0)