The purpose of this patch is to allow exporting of variables to parent environment variable scopes, not only to the nested scopes.
This does not break compatibility with any existing modules or GRUB configuration files/scripts. The introduced changed are: * The ‘export’ command became an extcmd. This was done to process the newly added options. This also added ‘--help’ and ‘--usage’ options to the command, but I think that it will be helpful to users of the GRUB. * The ‘export’ command accepts an ‘-g’/‘--global’ option now. It causes exporting the given variables not only to the newly created scopes, but also to any parent scope (recursively), when this scope exits. * To complement this behaviour, the option ‘-u’/‘--unexport’ was added to the ‘export’ command. Using this option undoes the exporting of the variable, so it becomes local again. * A function ‘grub_env_set_export_mode’ and its accompanying enum was created to allow un-exporting variables and making them global. These changes were performed to allow me creating complex menu-based pre-boot configuration interface for a live disk image on which I am currently working. With these changes, it is possible to create a submenu containing options that do not cause the bootloader to boot directly, but only affect further selected options. I hope that this feature will find some use in various so-called live disks or to provide a more user-friendly interface for configuring the system kernel than plain editing of a menuentry command line. There is one change which could seem to break compatibility with existing scripts; Before changes introduced in this patch, the ‘export’ command accepted environment variables starting with an ASCII hyphen, since it wasn't an extcmd. Now, it processes command-line options, so an extra ‘--’ must be added to process hyphen-prefixed variables. But in reality, any variable names starting with a hyphen can be only used in a handful of cases, such as setting their value, exporting them or displaying on the screen using the ‘set’ command. Their values _cannot_ be even used in essentially all commands, because the ‘$-something’ or ‘${-something}’ syntax is invalid. Therefore, I assume that this change would not break any existing GRUB scripts. Jiří Wolker (2): Exporting variables to upper levels Docs for the new options of the ‘export’ command docs/grub.texi | 10 +++++- grub-core/kern/env.c | 11 ++++-- grub-core/normal/context.c | 70 ++++++++++++++++++++++++++++++-------- include/grub/env.h | 11 +++++- 4 files changed, 84 insertions(+), 18 deletions(-) -- 2.45.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel