Based on this answer (as already linked by other answer), the following appears to work with GRUB's regexp
command (allows incrementing from any number 0-5, add more <from>,<to> pairs as needed):
num=0
incr="" ; for x in 0,1 1,2 2,3 3,4 4,5 5,6 ; do
regexp --set=1:incr "${num},([0-9]+)" "${x}"
if [ "$incr" != "" ] ; then
echo "$num incremented to $incr"
num=$incr
break
fi
done
Decrementing similarly works (just flipping two the regular expression parts):
num=6
decr="" ; for x in 0,1 1,2 2,3 3,4 4,5 5,6 ; do
regexp --set=1:decr "([0-9]+),${num}" "${x}"
if [ "$decr" != "" ] ; then
echo "$num decremented to $decr"
num=$decr
break
fi
done