
Task 1: Comments
In Bash scripts, comments are used to add explanatory notes or disable certain lines of code. Your task is to create a Bash script with comments explaining what the script does.
Script: comments_example.sh
#!/bin/bash
# This script demonstrates the use of comments in a Bash script
echo "Comments are helpful for explaining code."
Task 2: Echo
The echo command is used to display messages on the terminal. Your task is to create a Bash script that uses echo to print a message of your choice.
Script: echo_example.sh
#!/bin/bash
# This script prints a message to the terminal
echo "Welcome to the Shell Scripting Challenge!"
Task 3: Variables
Variables in Bash store data and can be referenced by their names. Your task is to create a Bash script that declares variables and assigns values to them.
Script: variables_example.sh
#!/bin/bash
# Declaring variables
name="Fauzeya"
age=24
# Displaying the values of the variables
echo "Name: $name"
echo "Age: $age"
Task 4: Using Variables
Now that you have declared variables, let's use them to perform a simple task. Create a Bash script that inputs two variables (numbers) and prints their sum using those variables.
Script: sum_example.sh
#!/bin/bash
# This script calculates the sum of two numbers
# Declaring variables
num1=10
num2=20
# Calculating the sum
sum=$((num1 + num2))
# Displaying the result
echo "The sum of $num1 and $num2 is: $sum"
Task 5: Using Built-in Variables
Bash provides several built-in variables that hold useful information. Your task is to create a Bash script that utilizes at least three different built-in variables to display relevant information.
Script: builtin_variables_example.sh
#!/bin/bash
# This script demonstrates the use of built-in variables
# Using built-in variables
echo "Script Name: $0" # Name of the script
echo "Number of Arguments: $# " # Number of arguments passed
echo "Current User: $USER" # Current logged-in user
Task 6: Wildcards
Wildcards are special characters used to perform pattern matching when working with files. Your task is to create a Bash script that utilizes wildcards to list all the files with a specific extension in a directory.
Script: wildcards_example.sh
#!/bin/bash
# This script lists all .txt files in the current directory
# Using wildcard to list .txt files
echo "Listing all .txt files in the current directory:"
ls *.txt
Conclusion
Each of these tasks introduces fundamental concepts in Bash scripting. As you complete these scripts, you’ll become more comfortable with comments, echovariables, built-in variables, and wildcards. Keep practicing and experimenting with these concepts!
Let me know if you need further explanations for any of these tasks!😊
About the author
Hi there! I'm Fauzeya 👩💻, a passionate DevOps Engineer with a background in Computer Science Engineering🎓. I’m committed to enhancing security🔒, efficiency⚙️, and effectiveness in software development and deployment processes. With extensive knowledge in cloud computing☁️, containerization📦, and automation🤖, I aim to stay updated with the latest tools and methodologies in the DevOps field. Currently, I’m on a journey to deepen my understanding of DevOps I enjoy sharing my learning experiences and insights through my blog, 📝where I cover topics related to DevOps practices, tutorials, and challenges. I believe in continuous growth and learning and am excited to connect with fellow tech enthusiasts and professionals🤝. Let’s embark on this journey together!🚀
Comments
Join the discussionGreat work




