[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reading File Name or Contents
From: |
Arbiel (gmx) |
Subject: |
Re: Reading File Name or Contents |
Date: |
Sat, 18 Jul 2015 17:30:59 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
Ubuntu's /etc/grub.d directory contains a 41_custom file which reads
#!/bin/sh
cat <<EOF
if [ -f \${config_directory}/custom.cfg ]; then
source \${config_directory}/custom.cfg
elif [ -z "\${config_directory}" -a -f \$prefix/custom.cfg ]; then
source \$prefix/custom.cfg;
fi
EOF
The generated code, included into grub.cfg, reads, if it exists, the
custom.cfg file.
You can hand-write this custom.cfg file to either "source" or
"configfile" your file. The path to your file can have been stored into
an environment variable (grub-editenv).
"sourcing" the file will add menu entries into the regular grub menu,
"configfiling" it will drop the regular menu and replace it by a brand
new menu, defined by the "menuentry" lines of your hand-written file.
Arbiel
Le 18/07/2015 05:33, Marc Smith a écrit :
> Ah, 'source' as in 'source' used with the shell... just figured they
> would label it as a command for the minimal GRUB shell, but doesn't
> appear they do (and maybe they don't list others as well). I'll try it
> soon, thanks again.
>
> --Marc
>
>
>
> On Fri, Jul 17, 2015 at 11:16 PM, Marc Smith <address@hidden
> <mailto:address@hidden>> wrote:
>
> JoÄo Ricardo Sares Teles de Matos: Thank you for the idea, but
> using an already generated grub.cfg file is a requirement (using
> grub-mkconfig isn't an option).
>
>
> On Fri, Jul 17, 2015 at 6:11 PM, Jordan Uggla
> <address@hidden <mailto:address@hidden>> wrote:
>
> On Fri, Jul 17, 2015 at 7:12 AM, Marc Smith
> <address@hidden <mailto:address@hidden>> wrote:
> > Hi,
> >
> > Looking for any possibility of reading the contents of a
> file (or even just
> > the file name) into a variable in a GRUB config file? I've
> read that command
> > substitution is not supported and no plans to add it, but is
> there any other
> > way?
> >
> > I've tried a couple other methods without success (in the
> grub.cfg file):
> > --snip--
> > while read ver_str;
> > do
> >Â Â Â something_with ${ver_str}
> > done < /version_file
> > --snip--
> >
> > OR
> >
> > --snip--
> > cat /version_file | while read ver_string;
> > do
> >Â Â Â something_with ${ver_str}
> > done
> > --snip--
>
> To get the version number from a file named "version_*", where
> the '*'
> is actually the version string, you could do something like this:
>
> insmod regexp
> filename=/directory/containing/file/version_*
>
> # Now we can, if we want to, extract just the version string
> regexp --set=version_string
> '/directory/containing/file/version_(.*)'
> "$filename"
>
> # Now $version_string contains just the version string.
>
> Please note that I'm not in a position to actually test the above
> code, so it likely contains mistakes.
>
>
> Thanks Jordan, I'll give it a shot.
>
> Â
>
>
> >
> > The goal is to read a "version string" from a file at boot
> with GRUB to
> > display different menu entries for different versions, but
> I'd even take
> > just getting the string from the file name at this point.
> Any ideas? My last
> > resort is to just use sed to modify grub.cfg when a new
> version of the OS is
> > installed (for a new GRUB menu entry), but I'd prefer not to
> do that unless
> > I have to.
> >
> > Or what about including another grub.cfg file and then in
> the included GRUB
> > config file just have the line "set ver_str=0.1.1" -- I was
> thinking using
> > the 'configfile' command would do this, but doesn't seem to
> work as I
> > expected.
>
> That method would also work fine, you just need to use
> "source" rather
> than configfile. The configfile command is used to load a file
> which
> will populate an entirely new grub menu whereas source in
> grub, much
> like in bash, executes commands in the current context.
>
>
> Okay, I'd prefer this method and I'll try it, but I don't see it
> in the GRUB documentation:
> http://www.gnu.org/software/grub/manual/grub.html
>
> Is that part of GRUB 2.00 or is it a feature in a newer version,
> or am I just missing?
>
>
> --Marc
>
> Â
>
>
> --
> Jordan Uggla (Jordan_U on irc.freenode.net
> <http://irc.freenode.net>)
>
>
>
>
>
> _______________________________________________
> Help-grub mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-grub
signature.asc
Description: OpenPGP digital signature