DEV Community

Kanav Gathe
Kanav Gathe

Posted on • Edited on

Day 8/90: Shell Scripting Challenge - The Basics 📝 #90DaysOfDevOps

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!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay