Day 38: Introduction to Scripting

Today I began exploring the foundational skill every DevOps engineer must know โ€” scripting. I focused on Bash scripting, the most widely used shell scripting language in Linux environments.


๐Ÿง  What is Scripting?

Scripting is writing a sequence of commands to automate tasks. In DevOps, scripts are used for:

  • Automation

  • Configuration

  • Monitoring

  • Provisioning

  • CI/CD workflows


๐Ÿš What is Bash?

Bash (Bourne Again SHell) is a Unix shell and command language. It's the default shell on many Linux distros and supports:

  • Command execution

  • Variables

  • Conditionals

  • Loops

  • Functions

  • File I/O


๐Ÿ›  Todayโ€™s Practice:

โœ… Basic Script Structure

#!/bin/bash
echo "Hello, DevOps World!"

โœ… Variables & User Input

read -p "Enter your name: " name
echo "Welcome, $name"

โœ… If Conditions

if [ "$name" == "admin" ]; then
    echo "Access granted"
else
    echo "Access denied"
fi

โœ… Loops

for i in {1..5}; do
    echo "Iteration $i"
done

โœ… Functions

greet() {
    echo "Hello from a function"
}
greet

๐Ÿ” Why Bash Scripting in DevOps?

  • Automates server provisioning

  • Supports CI/CD pipelines

  • Useful in Docker, Ansible, Kubernetes

  • Great for cron jobs and backups


๐Ÿ“š What Iโ€™ll Explore Next:

  • More in variables System variables

  • Shell script best practices

  • Commad line arguments

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir