Loop

For GRUB scripting language, looping in GRUB is very crude and simple. Keep in mind that GRUB does not have arithmetic functionalities. Hence, you can't do something like $((count - 1)) in POSIX shell. It's best to keep it to a Boolean type conditions.


You can use the following to control the loop actions:

  • continue - skip this loop and proceed to the next one
  • break - exit the loop immediately

For Loop

You can use for loop for predictable looping.


Basic

The very basic format is similar to POSIX version:

grub> for i in 1 2 3; do
> echo "current: $i"
> done
current 1
current 2
current 3
grub>

In script form:

for i in 1 2 3; do
        echo "current: $i"
done


While Loop

You can use while loop for unpredictable or conditional looping. Keep in mind that GRUB does not have arithmetic functionalities. Hence, you can't do something like $((count - 1)) in POSIX shell. It's best to keep it to a Boolean type conditions.


Basic

while [ controllable Boolean type conditions ]; do
        ...
done

Until Loop

You can use while loop for unpredictable or conditional looping. Keep in mind that GRUB does not have arithmetic functionalities. Hence, you can't do something like $((count - 1)) in POSIX shell. It's best to keep it to a Boolean type conditions.


Basic

until [ controllable Boolean type conditions ]; do
        ...
done

That's all about looping in GRUB scripting language.