DEV Community

Udoh Deborah
Udoh Deborah

Posted on

Day 8: Shell Scripting Challenge

Task 1: Comments in Bash Scripts

Create a script named greet_user.sh and add comment:

#!/bin/bash

# This script greets the user with a welcome message

# Ask for the user's name and store it in a variable
read -p "Enter your name: " name

# Display a personalized greeting
echo "Hello, $name! Welcome to the #90DaysOfDevOps Challenge!"

# End of script
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • #!/bin/bash tells the system this is a Bash script.

  • Lines starting with # are comments — they do not get executed, and are used to explain what each part of the script does.

  • Using comments is a best practice in scripting to make your code
    easier to understand and maintain.

✅ Task 2: Using echo in Bash
Create a file named echo_message.sh and add the following:

#!/bin/bash

# This script displays a motivational message
echo "I am one step closer to becoming a DevOps Engineer!"


Enter fullscreen mode Exit fullscreen mode

Explanation:

echo is used to print text to the terminal.
In this case, for example. it prints a custom message to keep you motivated on your DevOps journey!

✅ Task 3: Using Variables in Bash
Create a file named variables.sh and add the script:

#!/bin/bash

# This script demonstrates the use of variables

name="Deborah"
course="DevOps"
day=8

echo "Hello, $name!"
echo "Welcome to Day $day of the $course challenge!"

Enter fullscreen mode Exit fullscreen mode

Explanation:

name, course, and day are variables.

We use echo to print their values.

You reference a variable with a $ (e.g., $name).

✅ Task 4: Using Built-in Variables in Bash
Create a file named builtin_variables.sh and add the following code

#!/bin/bash

# This script demonstrates the use of built-in Bash variables

echo "Script name: $0"           # The name of the script
echo "Number of arguments: $#"   # Total number of arguments passed to the script
echo "All arguments: $@"         # All the arguments passed
echo "Current working directory: $PWD"  # The present working directory
echo "Home directory: $HOME"     # The home directory of the current user

Enter fullscreen mode Exit fullscreen mode

Explanation:

  • $0 → name of the script

  • $# → number of arguments passed

  • $@ → list of arguments passed

  • $PWD → current working directory

  • $HOME → user's home directory

✅ Task 5: Using Wildcards in Bash
Create a Bash script named wildcard_list.sh:

#!/bin/bash

# This script lists all files with a specific extension in the current directory

# Ask user for the extension
read -p "Enter the file extension (e.g. txt, sh, log): " ext

# Use wildcard to list all files with that extension
echo "Listing all *.$ext files in the current directory:"
ls *."$ext"

Enter fullscreen mode Exit fullscreen mode

Explanation:

  • Prompts the user to enter a file extension (e.g., txt, sh, log).

  • Uses the * wildcard to match all files ending in that extension.

  • Lists the matching files using the ls command.

✅ Task 6: Create a single bash script that completes all the tasks mentioned above

#!/bin/bash

#########################################
# Day 8: Shell Scripting Challenge
# This script demonstrates:
# 1. Comments
# 2. Echo command
# 3. Variables
# 4. Built-in variables
# 5. Reading User Input
# 6. Using Wildcards
#########################################

# 1. Echo command - Displaying a welcome message
echo "Welcome to Day 8 of the 90DaysOfDevOps Challenge!"

# 2. Variables - Declaring and assigning values
name="Deborah"
challenge="90DaysOfDevOps"
day=8

# Displaying the values of the variables
echo "Hello $name, welcome to Day $day of the $challenge challenge!"

# 3. Built-in Variables - Demonstrating usage
echo "Current script name: $0"
echo "Total number of arguments passed: $#"
echo "Current working directory: $PWD"

# 4. Reading User Input - Collecting dynamic input from the user
read -p "Enter your favorite Linux command: " command
echo "Awesome! Your favorite command is: $command"

# 5. Argument Input - Accepting values from the command line
# Example: ./day8_script.sh DevOps Linux
role=$1
platform=$2

echo "You are learning $role on $platform platform!"

# 6. Using Wildcards - Listing files with a specific extension
read -p "Enter a file extension to search for (e.g. txt, sh): " ext
echo "Listing all *.$ext files in the current directory:"
ls *."$ext" 2>/dev/null || echo "No files found with .$ext extension."

# End of script
echo "Script execution complete!"

Enter fullscreen mode Exit fullscreen mode

✅ Task 7: create a GitHub repository and commit your script to it

  • Step 1: Create a New GitHub Repository
    Go to https://github.com

  • Click the "+" icon at the top right → select "New repository"

  • Fill in the details:

  • Repository name: 90DaysOfDevOps-Day8

  • Description: Bash script covering shell scripting basics — Day 8 of the 90DaysOfDevOps challenge.

  • Choose Public or Private

  • Click Create repository

✅ Step 2: Commit Your Script to the Repository

# Step 1: Clone the repo (replace with your repo's actual URL)
git clone https://github.com/your-username/90DaysOfDevOps-Day8.git

# Step 2: Move into the project folder
cd 90DaysOfDevOps-Day8

# Step 3: Copy or move your script into the folder
cp /path/to/day8_script.sh .

# Step 4: Stage the script
git add day8_script.sh

# Step 5: Commit the script with a message
git commit -m "Add Day 8 shell scripting challenge script"

# Step 6: Push to GitHub
git push origin main

Enter fullscreen mode Exit fullscreen mode

Shell scripting is a powerful tool for automation, and today’s tasks reinforced just how essential it is for DevOps engineers.

Top comments (0)