Welcome back to Day 3 of the Linux Bash Course! 🚀
Now that we know how to use variables, it's time to start automating tasks. In this lesson, we are diving into Loops—specifically for loops—and learning how to skip specific parts of a loop using the continue command.
👨💻 What we cover in this lesson:
In this video, we write a script that counts from 1 to 5, but completely skips the number 2.
🔍 How it works:
The Loop (for i in {1..5}; do): We are telling Bash to create a loop that runs 5 times. The variable i will automatically become 1, then 2, then 3, and so on, up to 5.
The Condition (if [[ $i -eq 2 ]]; then): Inside the loop, we check the current value of i. This line translates to: "If i is exactly equal to 2, then do the following..."
Skipping with Continue (continue): This is the magic word! When Bash sees continue, it stops the current cycle immediately and jumps straight back to the top of the loop to start the next number. It completely bypasses the echo command for that specific cycle.
🔔 Don't forget to:
👍 Like this video if it helped you understand looping!
✅ Subscribe to AI & Cyber Academy for more daily Linux and cybersecurity tutorials.
💬 Leave a comment below: What other types of loops do you want to learn?
#Linux #Bash #BashScripting #LinuxCourse #LearnToCode #CyberSecurity #Terminal #ForLoop