Day 8/90: Shell Scripting Challenge - The Basics πŸ“ #90DaysOfDevOps

Kanav Gathe - Oct 23 - - Dev Community

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
Enter fullscreen mode Exit fullscreen mode

2. Echo Command Usage

#!/bin/bash

echo "Welcome to Shell Scripting!"
echo "This is Day 8 of #90DaysOfDevOps"
Enter fullscreen mode Exit fullscreen mode

3. Variables Declaration

#!/bin/bash

# Declaring variables
name="DevOps Engineer"
course="Shell Scripting"
day=8
current_dir=$(pwd)
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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!

. . . . . . . . . . . . . . .