Shell Scripting Challenge

Shell Scripting Challenge

ยท

2 min read

๐ŸŒŸ Tasks Overview

  1. ๐Ÿ“ Comments

    • Add explanatory notes in the script.
  2. ๐ŸŽ‰ Echo

    • Use the echo command to display a message.
  3. ๐Ÿ” Variables

    • Declare variables and assign values to them.
  4. โž• Using Variables

    • Take two variables (numbers) as input and print their sum.
  5. ๐Ÿ› ๏ธ Using Built-in Variables

    • Use at least three built-in variables to display information.
  6. ๐Ÿ“‚ Wildcards

    • List all files with a specific extension in a directory.
#!/bin/bash

# Task 1: Comments
# This script demonstrates various bash scripting concepts including comments,
# echo, variables, using variables for arithmetic operations, built-in variables,
# and wildcards to list files with a specific extension.

# Task 2: Echo
# Display a welcome message on the terminal
echo "Welcome to the Bash Scripting Challenge!"

# Task 3: Variables
# Declare variables and assign values
name="DevOps Learner"
favorite_number=42

# Print the variables using echo
echo "My name is $name and my favorite number is $favorite_number."

# Task 4: Using Variables
# Prompt the user to enter two numbers
echo "Please enter two numbers to calculate their sum:"

# Read the first number
read -p "Enter the first number: " num1

# Read the second number
read -p "Enter the second number: " num2

# Calculate the sum of the two numbers
sum=$((num1 + num2))

# Display the sum
echo "The sum of $num1 and $num2 is: $sum"

# Task 5: Using Built-in Variables
# Display the current user's name, the script's name, and the current date
echo "Current user: $USER"
echo "Script name: $0"
echo "Current date: $(date)"

# Task 6: Wildcards
# List all .txt files in the current directory
echo "Listing all .txt files in the current directory:"
ls *.txt

# End of script
ย