String manipulation in Grub2

If you want scriptability in Grub2, you need the lua support, which is not part of the released version. It's part of the grub-extras, and you can get the source from the bazaar repository. You'll need to rebuild Grub2 from source. I don't think there's any documentation apart from the source, though you can ask for help on the grub-devel mailing list. Good luck.


The regexp command can be used to do limited string manipulation.

https://www.gnu.org/software/grub/manual/grub/grub.html#regexp

untested example:

regexp --set base "(....)00" "$reg"
if [ "$base" != "" ]; then
    setpci "${base}18" ...
fi