๐ DevSecOps Journey โ Day 8

Mastering Shell Scripting for DevOps Automation
โจ Building the foundations for reliable automation workflows
Shell scripting is one of the most essential skills in DevOps & DevSecOps.
Today, I explored how shells work, why automation matters, and how scripting makes deployments, server setups, and CI/CD processes more efficient and reliable.
๐ What is a Shell?
A shell is a command-line interface (CLI) that allows users to interact with the operating system and execute commands.
๐ Common Shell Types
๐ฆ bash
๐จ sh
๐ช zsh
๐ python shell
Shells allow us to run commands, automate workflows, and build scripts that execute consistently across environments.
โ๏ธ Why Shell Scripting Matters in DevOps
In real-world DevOps environments:
Installing Docker
Configuring Jenkins
Deploying applications
Running validations
โฆoften require multiple manual commands.
With Shell Scripting, we can:
โ๏ธ Combine all commands into one file
โ๏ธ Run them in a single execution
โ๏ธ Share scripts across teams
โ๏ธ Automate builds, deployments & server provisioning
โ๏ธ Reduce human error
Shell scripting = faster, safer, predictable automation.
๐งญ Understanding the Shebang (#!)
The first line of most shell scripts is:
#!/bin/bash
#!โ Shebang/bin/bashโ tells OS to execute this script using bash
If you skip the shebang, the script can still run with:
bash filename.sh
๐งฉ Variables & Basic Operations
โ๏ธ Declaring Variables
name="Jayesh"
echo "Hello $name"
age="24"
echo "Your age is $age"
โ๏ธ Arithmetic
x=4
y=7
sum=$((x+y))
echo "$sum is "
โ๏ธ String Concatenation
greetings="Hello"
name="Jayesh"
message="$greetings, $name"
echo "$message"
โ๏ธ String Length
string="Vishal Patil"
length=${#string}
echo "Length : $length"
๐ Echo Behavior & Special Characters
variable="Hello World"
echo "$variable"
echo '$variable'
echo $variable
echo "both '$variable'"
special_char="\$"
echo "special char - $special_char"
๐ User Input Handling
โ๏ธ Hidden Password Input
read -s -p "Your password is " password
echo "Password has been set $password"
โ๏ธ Timeout-Based Input
read -t 6 -p "Enter something in 6 second " timed_out
echo "$timed_out"
๐ง Conditional Statements
num=10
if [ $num -gt 10 ]; then
echo "Number is greater than 10"
elif [ $num -eq 10 ]; then
echo "Number is equal to 10"
else
echo "Number is less than 10"
fi
๐ Switch / Case Statements
fruit="apple"
case $fruit in
"apple")
echo "it is an apple"
;;
"banana")
echo "it is banana"
;;
"mango")
echo "it is mango"
;;
*)
echo "Unknown fruit"
;;
esac
๐ Loops in Shell Scripting
โ๏ธ For Loop โ Numeric
for i in {1..21}; do
echo "numbers $i"
done
โ๏ธ For Loop โ Array
fruits=("shimpi" "patil" "deshmukh")
for fruit in "${fruits[@]}"; do
echo "fruits name $fruit"
done
โ๏ธ While Loop
counter=1
while [ $counter -le 5 ]; do
echo "count : $counter"
counter=$((counter+1))
done
echo "loop finished"
โ๏ธ Until Loop
counter=1
until [ $counter -ge 5 ]; do
echo "count : $counter"
counter=$((counter+1))
done
echo "loop finished"
๐งฎ Functions โ Local & Global Variables
โ๏ธ Local Variable Example
calculate_sum() {
local num1="$1"
local num2="$2"
local sum=$((num1+num2))
echo "$sum"
return "$sum"
}
result=$(calculate_sum 10 20)
echo "sum is $result"
โ๏ธ Global vs Local
global_var="Im global variable"
local_variable() {
local local_var="Hello I am local"
echo "Inside function $local_var"
echo "outside function $global_var"
}
local_variable
echo "1111 $local_var" # Not accessible
echo "2222 $global_var" # Accessible
โ๏ธ String Manipulation
โ๏ธ Extract Substring
string="Hello,world"
substring=${string:6:5}
echo "$substring"
โ๏ธ Replace Text
string1="ms dhoni, def"
search="def"
replace="faf du plessis"
result=${string1//$search/$replace}
echo "org $string1"
echo "org $result"
๐ฏ Why Shell Scripting Matters in DevOps/DevSecOps
Shell scripting powers automation for:
โ๏ธ CI/CD pipelines
๐ Automated deployments
๐ฆ Server provisioning
๐ Log analysis
๐ Security checks
โ๏ธ Cloud operations
๐ System monitoring
Mastering shell scripting = mastering DevOps automation.
โ Day 8 Summary
Today, I learned and practiced:
Variables, arithmetic & strings
User input, password, timeout
Conditionals & switch-case
Loops (for, while, until)
Functions + local/global variables
String manipulation (extract, replace)
These scripting fundamentals are essential for writing automation scripts used in deployments, CI/CD workflows, cloud platforms, and secure engineering systems.




