while Loop

noun

say it: “WYL LOOP” /ˈwaɪl ˈlup/

A loop that keeps repeating its commands for as long as a condition stays true.

What is a while loop in bash?

A while loop runs a command and, as long as it works (exit code 0), runs the lines between do and done, then asks again. With IFS= read -r line and done < file, it works through a file one whole line at a time.

while IFS= read -r line; do
  echo "Read: $line"
done < flight-log.txt

In a sentence

  • “The while loop read the flight log one line at a time.”
  • “A while loop counted down from 5 while n was greater than 0.”

Level: Journeyman · More Unix terms at this level

Updated

In other subjects