Skip to contentSkip to conversation

submenu fails to see variables

DISCUSSION Olaf Hering 4 participants 5 messages Sep 6, 2021 – Sep 8, 2021

lore
Share & tools
lore
#0 lore raw

For some reason global variables are not seen in a submenu {} section. Does anyone happen to know why this behavior is useful?

Pseudocode:

set var=val
menuentry "me" {
set
echo "var ${var}"
sleep 3
}

submenu "sm" {
set
echo "var ${var}"
sleep 3
}

Seen with grub 2.02 and 2.04.

Thanks,
Olaf

#1 lore raw
Quoted 3 lines · Olaf Hering

For some reason global variables are not seen in a submenu {} section. Does anyone happen to know why this behavior is useful?

You need to export variable to make it visible in submenu

Quoted 26 lines

Pseudocode:

set var=val
menuentry "me" {
set
echo "var ${var}"
sleep 3
}

submenu "sm" {
set
echo "var ${var}"
sleep 3
}

Seen with grub 2.02 and 2.04.

Thanks,
Olaf
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 4 lines · Vladimir 'phcoder' Serbinenko

Le lun. 6 sept. 2021 à 12:49, Olaf Hering <[email protected]> a écrit :
For some reason global variables are not seen in a submenu {} section. Does anyone happen to know why this behavior is useful?
You need to export variable to make it visible in submenu

Thanks. This was less than obvious. I did not expect a command named 'export' in the context of grub.

The documentation needs to be updated to state what the difference between 'set key=val', 'export key=val' and plain 'key=val' actually is.

Olaf

#3 lore raw
Quoted 11 lines · Olaf Hering
Quoted 4 lines · Vladimir 'phcoder' Serbinenko

Le lun. 6 sept. 2021 à 12:49, Olaf Hering <[email protected]> a écrit :
For some reason global variables are not seen in a submenu {} section. Does anyone happen to know why this behavior is useful?
You need to export variable to make it visible in submenu

Thanks. This was less than obvious. I did not expect a command named 'export' in the context of grub.

The documentation needs to be updated to state what the difference between 'set key=val', 'export key=val' and plain 'key=val' actually is.

I have seen somewhere that some distros applied a patch to simply export all variables always; or like not to create new contexts for submenus, to keep the variable space the same.

Imho keeping variable space global, and exported by default seems to lead to least surprises. But it is a behaviour change/break.

#4 lore raw
Quoted 11 lines · Dimitri John Ledkov
Quoted 10 lines · Olaf Hering
Quoted 4 lines · Vladimir 'phcoder' Serbinenko

Le lun. 6 sept. 2021 à 12:49, Olaf Hering <[email protected]> a écrit :
For some reason global variables are not seen in a submenu {} section. Does anyone happen to know why this behavior is useful?
You need to export variable to make it visible in submenu

Thanks. This was less than obvious. I did not expect a command named 'export' in the context of grub.

Quoted 8 lines
Quoted 1 line

The documentation needs to be updated to state what the difference between 'set key=val', 'export key=val' and plain 'key=val' actually is.

I have seen somewhere that some distros applied a patch to simply export all variables always; or like not to create new contexts for submenus, to keep the variable space the same.

Imho keeping variable space global, and exported by default seems to lead to least surprises. But it is a behaviour change/break.

I would prefer to keep behavior as is and document it.

Dimitri, Olaf, could one of you do it?

Daniel