Day 8 Task: Shell Scripting Challenge

Shell scripting in Bash is an essential skill for any development environment. It allows for automating tasks, managing systems efficiently, and performing repetitive tasks with ease. In this guide, we will walk through some fundamental concepts of shell scripting with practical tasks to solidify your understanding.

Task 1: Comments

In bash scripts, comments are used to add explanatory notes or disable certain lines of code.

#!/bin/bash

# First line of the script is the shebang which tells the system how to execute

Task 2: Echo

The echo command is used to display messages on the terminal. It's a basic but powerful way to interact with the user and display information.

# Task  2: Echo
echo "Welcome to Day 8 of the DevOps Challenge!"

Task 3: Variables

Variables in bash are used to store data and can be referenced by their name. They help in making scripts dynamic and reusable.

# Task  3: Variables
variable1="Hello"
variable2="Bash"

Task 4: Using Variables

Now that you have declared variables, let's use them to perform a simple task. This script takes two variables (numbers) as input and prints their sum using those variables.

#!/bin/bash
# Declaring variables
num1=5
num2=10
# 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.

#!/bin/bash
# Displaying built-in variables
echo "current user: $USER"
echo "Home Directory: $HOME"
echo "Shell: $Shell"
echo "Number o0f arguements: $#"

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.

#!/bin/bash
# Listing all .txt files in the current directory
echo "Text files in the current directory:"
ls *.txt

Create a single bash script that completes all the tasks mentioned above.

#!/bin/bash

# First line of the script is the shebang which tells the system how to execute

# Task  2: Echo
echo "Processed by Pooja's script"

# Task  3: Variables
variable1="Hello"
variable2="Bash"

# Task  4: Using Variables
greeting="$variable1, $variable2!"
echo "$greeting Welcome to the world of Bash scripting!"

# Task  5: Using Built-in Variables
echo "My current bash path - $BASH"
echo "Bash version I am using - $BASH_VERSION"
echo "PID of bash I am running - $$"
echo "My home directory - $HOME"
echo "Where am I currently? - $PWD"
echo "My hostname - $HOSTNAME"

# Task  6: Wildcards
echo "Files with .txt extension in the current directory:"
ls *.txt
0
Subscribe to my newsletter

Read articles from Yuvraj Nath Chouhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Yuvraj Nath Chouhan
Yuvraj Nath Chouhan

🚀 Aspiring DevOps & DevSecOps Engineer | Cloud DevOps (Azure & AWS) | Automation & Security Champion | Passionate Learner🌐 Hi, I’m Yuvraj! 🔥 I'm embarking on an exciting journey in the world of DevOps & DevSecOps, armed with hands-on expertise and a drive to excel. From automating tasks to building robust CI/CD pipelines, I’m dedicated to turning complex challenges into efficient and secure solutions. What I Bring to the Table: ●Linux & Shell Scripting 🖥️ Automating processes and mastering command-line operations. ●Git & Git Branching 🔀 Seamless version control for effective collaboration. ●Build Tools 🔧 (Maven & npm) Crafting stable builds for quality software. ●CI/CD Tools 🚄 (Jenkins, GitHub Actions, Azure DevOps, GitLab CI/CD) Ensuring smooth & automated deployments. ●Security in DevOps 🛡️ Embedding security at every stage to safeguard development processes. ●Artifact Management 📦 (Nexus & Azure Artifacts) Managing software versions efficiently. ●Containerization & Orchestration 🐳⎈ (Docker & Kubernetes) Deploying scalable, agile applications. ●Infrastructure as Code (IaC) 📜 (Terraform & Ansible) Automating environment provisioning. ●Monitoring & Troubleshooting 🔍 Keeping systems in check with proactive issue resolution. ●Real-world & Corporate Projects 🌟 Hands-on experience with practical implementations. ✨ Always eager to learn, collaborate, and innovate! ✨ I’m ready to transform my academic knowledge and project experiences into real-world impact. Let’s connect and explore how we can drive meaningful change together! 🤝