Grub2 Function parameters

3

Grub2 allows for powerful scripting capabilities. if, while, function, etc all mean the language is pretty powerful (Turing complete?).

However, I cannot figure out how to pass parameters in grub2.

grub> function hello {
>        echo hello $1
>     }
grub> 
grub> hello world
hello
grub> # i'd expect to see 'hello world' here
grub> # instead in only get 'hello'
grub> 
grub> # this works however
grub> 1=world
grub> hello
hello world
grub>

Does Grub2 allow passing parameters to user defined functions?

deft_code

Posted 2010-09-09T17:15:41.353

Reputation: 229

Answers

2

Function parameters only appeared in Grub in May 2010. At the moment the last grub release is 1.98 from March 2010, so if you want them, you have to get Grub from the Bazaar repository.

If you hope to do serious programming in Grub, though, you'll have to go all the way to lua support.

Gilles 'SO- stop being evil'

Posted 2010-09-09T17:15:41.353

Reputation: 58 319

Thanks. I have been using the Lua. However, I don't think there will ever be a way to pass parameters to Lua from menu entries. The best I can do is set a variable before invoking the script. My idea was to have a grub function forward its parameters to the Lua script. This way my menu entries look like regular function calls, but the guts can still be Lua. – deft_code – 2010-09-09T18:15:24.727