Tools: My Cloud and DevOps Journey : Day 1
Start From Linux with Shell Scripting for DevOps : Shell scripting is like learning a new language — at first, the syntax feels cryptic, but every small win builds confidence. Over time, I’ve discovered not just commands, but ways of thinking about automation, problem solving, and DevOps workflows. Here’s a reflection on the lessons, challenges, and insights I’ve gathered so far. Early Lessons Learned File and Directory Operations
Use find when you need to search across directories.Use [ -f ] when you already know the exact path you want to check.:> filename → resets a file to empty without deleting it.exit 1 → stops the script at the failure point.echo $? → inspects the exit code of the last command.👉 These basics taught me how to control flow and handle files safely. Conditional Logic[ ] → used for conditions (strings, files, etc.).[[ ]] → more powerful, supports pattern matching.(( )) → used for arithmetic comparisons.Commands can run directly in if without [ ]. /dev/null → suppresses normal output.2>&1 → suppresses error messages too. Challenge: Forgetting spaces inside [ ] caused errors like “command not found”. Lesson: Always put spaces around brackets. 🔄 Loops: Thinking in Iterations🛠️ How to Think About LoopsFor loop → “Do this for each item.” (fixed list or range).While loop → “Keep doing this until the condition fails.”Until loop → “Keep doing this until the condition succeeds.”Array loop → Use "${array[@]}" with for because you know the items. 🔄 Types of Loops in Shell Use case: Iterating over files in a directory. Use case: Monitoring a service until it starts. Use case: Continuous monitoring tasks. Rule of ThumbInside loops:for file in *.sh → no need for [[ ]].Use [[ ]] for string/pattern conditions.Use (( )) for numeric conditions.Outside loops: same rule applies. ⚙️ DevOps ConnectionFor loop + [[ ]] → Iterate files and check extensions, permissions, or patterns.For loop + (( )) → Iterate numbers (like retries, ports, IDs).While loop → Monitor service status or retry logic.Until loop → Wait until a condition succeeds (e.g., deployment ready). 🧩 Challenges We FacedParsing errors: Forgetting spaces in [ ].Percentage vs actual size: df -h vs du -sh.Suppressing output: Learning >/dev/null 2>&1.Exit codes: Understanding how echo $? helps debug scripts. ✅ Key TakeawaysThink in conditions: [ ] for files/strings, [[ ]] for patterns, (( )) for numbers.Think in loops: For known ranges → for; for monitoring → while; for waiting → until.Normalize values: Use numfmt to convert human-readable disk sizes into integers.Fail fast: Use exit 1 to stop at the failure point.
Debug smartly: Use echo $? to check exit codes. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to ? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse