bash loops

Updated: 26 September 2025

until loop

Similar to a while loop, except that the loop executes until the test-command executes successfully. As long as this command fails, the loop continues.

until test-command; do
    consequent-commands;
done

for loop

my_array=("apple" "banana" "orange" "grape")

for element in "${my_array[@]}"; do
    echo "Current element: $element"
done

Leave a comment