0PricingLogin
Linux Command Line Mastery · Lesson

Loops: `for`, `while`, `until`

Automate repetitive tasks by mastering different types of loops in shell scripting.

Why Use Loops?

Imagine you need to perform the same action many times, like saying 'Hello' to everyone in a list, or counting from 1 to 100. Doing this manually would be tedious and error-prone.

This is where loops come in! Loops allow your script to repeat a set of commands multiple times, saving you effort and making your scripts more efficient.

Looping Through Items with `for`

The for loop is perfect when you know exactly what items you want to iterate over. It goes through a list, processing each item one by one.

Its basic syntax looks like this:

  • for item in list; do
  • # commands to run for each item
  • done

The item variable will hold each value from the list in turn.

All lessons in this course

  1. Variables, Input, and Output
  2. Conditional Statements: `if`, `else`, `case`
  3. Loops: `for`, `while`, `until`
  4. Functions and Arguments in Shell Scripts
← Back to Linux Command Line Mastery