Grub throws "can't find command `['." when adding conditional to grub.cfg

1.6k views Asked by At

It was my understanding that grub supports a small subset of bash. Their documentation doesn't go into super detail, other than it "supports conditionals", etc.

I am trying to run a simple if.

grub> if [ "${myvar}" = "fred" ]; then
> echo "test"
> fi
error: can't find command `['.

Anybody have an idea? I am using grub2-efi 2.00.

1

There are 1 answers

0
NuclearPeon On

You are missing a grub2 module in order to run if tests.

I'm running Gentoo on a PowerPC system (PPC64 G5 machine) and doing a default grub-mkconfig then booting from it gives me the error in your question.

Since bash has that syntax support, I figured it was simply a grub module that needed to be added (I had been doing work with grub modules recently). tl;dr: You need to load the appropriate grub module and then the error goes away.

The first step is to find out what modules you have. For me, it's whatever is available in my /boot/grub/powerpc-ieee1275/ folder. There's also modules in /usr/lib/grub/powerpc-ieee1275/.

I wrote up a list of modules I thought I needed:

normal
eval
read
test
test_blockarg
trig
true

I then added them to my /etc/default/grub file:

GRUB_PRELOAD_MODULES="normal eval read test test_blockarg trig true"

I did not find an entry for GRUB_PRELOAD_MODULES in the config file, so I had to do some searching to find out how. I want these modules to be added every time I generate the grub config file, which means putting them in the 00_header portion of grub.

Then I recreated the configuration file:

grub-mkconfig -o /boot/grub/grub.cfg

The modules were in the header and things worked perfectly on reboot.

If I had to guess: you probably only need the test module to enable if statements.