Day 8 Task: Shell Scripting Challenge
DevOps | Cloud Practitioner | AWS | GIT | Kubernetes | Terraform | ArgoCD | Gitlab
Here’s a bash script that fulfills all the tasks for Day 8 of the Shell Scripting Challenge, with comments explaining each section.
#!/bin/bash
# Task 1: Comments
# This script demonstrates various basic concepts in bash scripting including comments, echo, variables, using variables, built-in variables, and wildcards.
# Task 2: Echo
# Using the echo command to print a message to the terminal.
echo "Welcome to Day 8 of the Bash Scripting Challenge!"
# Task 3: Variables
# Declaring and assigning values to variables.
name="Amit"
day=8
# Task 4: Using Variables
# Using the variables declared above to print personalized information.
echo "Hello, $name! You are working on Day $day of the challenge."
# Task 4 continued: Adding two variables
# Declare two number variables and calculate their sum
num1=10
num2=25
sum=$((num1 + num2))
# Output the sum
echo "The sum of $num1 and $num2 is $sum."
# Task 5: Using Built-in Variables
# Bash built-in variables include $0, $USER, $SHELL, $PWD, $HOSTNAME, etc.
# Below we will use some of these built-in variables to display information.
# Display the script name (which is stored in $0)
echo "This script is called: $0"
# Display the current logged-in user ($USER)
echo "Current user: $USER"
# Display the shell being used ($SHELL)
echo "Shell being used: $SHELL"
# Display the current working directory ($PWD)
echo "Current working directory: $PWD"
# Task 6: Wildcards
# Wildcards are used to match file patterns. The '*' wildcard matches all files.
# We'll use a wildcard to list all '.sh' files in the current directory.
echo "Listing all '.sh' files in the current directory:"
ls *.sh
# End of script
echo "Bash scripting challenge completed!"
Explanation of the Script:
Task 1: Comments: Every section of the script is documented with comments for clarity.
Task 2: Echo: A simple message is printed to the terminal using
echo.Task 3: Variables: Variables
nameanddayare declared and assigned values. These values are then used in the next step.Task 4: Using Variables: The script calculates the sum of two numbers and outputs the result.
Task 5: Built-in Variables: The script uses bash built-in variables like
$0,$USER,$SHELL, and$PWDto display useful information about the script and the system environment.Task 6: Wildcards: The script lists all
.shfiles in the current directory using thels *.shcommand, which demonstrates the use of wildcards.
How to Run:
Save this script as
challenge_day8.sh.Give execution permission:
chmod +x challenge_day8.sh or chmod 766 challenge_day0.shRun the script:
./challenge_day8.sh
Submission:
Check over github


