Bash: Or in an until or while loop

Problem

How do you write a while or until loop in bash which uses or in the condition?

Solution

The example is going to run until $a is A, $b is B, or $c is C

#Example until loop waiting for one of the 3 conditions to evaluate to false. This loop will only run through once.
a='' 
until [[ "$a" == 'A' || "$b" == 'B' || "$c" == 'C' ]]; do
   echo "waiting..."
   echo "\$a = $a"
   sleep 2
   a='A'
done

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.