[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: assigning a value to a variable in 00_header
From: |
Andreas Born |
Subject: |
Re: assigning a value to a variable in 00_header |
Date: |
Wed, 02 May 2012 19:18:35 +0200 |
----- Ursprüngliche Mitteilung -----
> Sorry,
> the source code examples I've sent are from grub.cfg and not from
> 00_header - in 00_header a $ needs to be escaped with \
>
> Greetings
> Joachim
>
> Am 02.05.2012 15:12, schrieb Joachim Mammele:
> > Hi everybody,
> >
> > I'd like to add a value to a user variable in 00_header but I get the
> > error "not an assignment".
> > but if I echo directly the value everything works fine.
> >
> > What can I do? How can I use a variable my_variable? Is there another
> > way to check for different values of \$? ?
> >
> > Any help would be appreciated.
> >
> > Greetings
> > Joachim
> >
> >
> > this is what is working fine:
> >
> > checkfrontkeys
> > echo "pressed key: \$?"
> >
> >
> > -------------
> >
> > this is what I'm struggling with (I've also been trying to use "case
> > \$? "instead of "if $pressed_key" but this didn't work neither):
Why the use of \ with case?
> >
> > checkfrontkeys
> > set pressed_key = $?
You seem to have a space here. In (ba)sh generally and not only grub2 no spaces
are allowed between the assignment operator and the respective
identifier/argument.
This should works:
set pressed_key=$?
> > echo "pressed key: "
> > echo $pressed_key
> > echo "\n"
> >
> > if [ $pressed_key == 1 ]; then
> > echo "pressed 1"
> > set default="1"
> > elif [ $pressed_key == 2]; then
> > echo "pressed 2"
> > set default="2"
> > elif [ $pressed_key == 3]; then
> > echo "pressed 3"
> > set default="3"
> > elif [ $pressed_key == 4]; then
> > echo "pressed 4"
> > set default="4"
> > else
> > echo "nothing pressed\n"
> > set default="6"
> >
> > fi
I don't see how you should need this. Assigning a numeric value to default
directly works fine here. I guess a case (not sure whether implemented) or some
other sort of sanity checking should be enough.
Be aware too that menuentries are numered starting with zero.
> >
> > echo "default = ${default}\n"
> > echo "after checkfrontkeys"
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > Grub-devel mailing list
> > address@hidden
> > https://lists.gnu.org/mailman/listinfo/grub-devel
>