Introduction
On Day 2 of my DevOps journey, I took my first steps into Bash scripting. Since automation is at the heart of DevOps, learning how to write scripts that execute tasks efficiently is a crucial skill. I explored the fundamentals of Bash scripting, including variables, loops, and basic scripting commands.
Why Learn Bash Scripting?
Bash scripting is essential in DevOps because it enables:
✅ Task automation – Reduce manual work by scripting repetitive tasks.
✅ System administration – Manage files, users, and processes efficiently.
✅ Pipeline integration – Automate deployments and CI/CD workflows.
My Key Learnings Today
1️⃣ Writing My First Bash Script
I started by creating a simple script and learning how to execute it.
Used
nano
andvim
to write scripts.Learned about the shebang (
#!/bin/bash
) to define the script interpreter.Made the script executable using
chmod +x
script.sh
.
2️⃣ Working with Variables & User Input
Declared and used variables:
name="Prathamesh" echo "Hello, $name!"
Read user input using
read
:echo "Enter your name:" read username echo "Welcome, $username!"
3️⃣ Using Conditional Statements
I explored how to use if-else
to create decision-making scripts:
echo "Enter a number:"
read num
if [ $num -gt 10 ]; then
echo "The number is greater than 10."
else
echo "The number is 10 or less."
fi
4️⃣ Loops in Bash
Loops make automation powerful. I learned:
For loop:
for i in {1..5} do echo "Iteration $i" done
While loop:
count=1 while [ $count -le 5 ] do echo "Count: $count" ((count++)) done
Challenges I Faced
🔴 Remembering syntax, especially for conditions and loops.
🔴 Understanding how variables work without explicit data types.
🔴 Handling script execution errors.
What’s Next? (Day 3 Plan)
📌 Learn functions in Bash scripting.
📌 Automate simple system tasks like file backups and log monitoring.
📌 Explore cron jobs for scheduling scripts.
Bash scripting is proving to be a game-changer for automation. Excited to dive deeper tomorrow! 🚀
2/n
#DevOps #BashScripting #Automation #100DaysOfDevOps