Day 8: Shell Scripting Challenge - The Basics 🚀
Hello DevOps enthusiasts! 👋 Welcome to Day 8 of the #90DaysOfDevOps challenge. Today, we're learning basic shell scripting concepts through practical examples.
Task Solutions 💻
1. Comments in Shell Script
#!/bin/bash
# This is a shell script that demonstrates various basic concepts
# Author: DevOps Engineer
# Date: October 2024
# Version: 1.0
2. Echo Command Usage
#!/bin/bash
echo "Welcome to Shell Scripting!"
echo "This is Day 8 of #90DaysOfDevOps"
3. Variables Declaration
#!/bin/bash
# Declaring variables
name="DevOps Engineer"
course="Shell Scripting"
day=8
current_dir=$(pwd)
4. Using Variables
#!/bin/bash
# Take two numbers as input
read -p "Enter first number: " num1
read -p "Enter second number: " num2
# Calculate and show sum
sum=$((num1 + num2))
echo "The sum of $num1 and $num2 is: $sum"
5. Built-in Variables
#!/bin/bash
echo "Script Name: $0"
echo "Current User: $USER"
echo "Home Directory: $HOME"
echo "Present Working Directory: $PWD"
echo "Hostname: $HOSTNAME"
6. Using Wildcards
#!/bin/bash
# List all shell scripts
echo "Shell Scripts in current directory:"
ls *.sh
# List all text files
echo "Text files in current directory:"
ls *.txt
Combined Script Example 🔧
#!/bin/bash
# Comments explaining script purpose
# This script demonstrates basic shell scripting concepts
# Echo command
echo "Basic Shell Script Demo"
# Variables
name="DevOps Engineer"
day=8
# Using variables
echo "Hello, I am a $name"
echo "This is Day $day of #90DaysOfDevOps"
# Built-in variables
echo "Running from: $PWD"
echo "By user: $USER"
# Wildcards
echo "Script files:"
ls *.sh
Key Takeaways 💡
- Comments make code readable and maintainable
- Echo commands display output
- Variables store and manage data
- Built-in variables provide system information
- Wildcards help in pattern matching
Bash #DevOps #Linux #Scripting #90DaysOfDevOps
This is Day 8 of my #90DaysOfDevOps journey. Keep scripting and automating!
Top comments (0)