5

I want to customize a little my GRUB 2 bootloader, so I'm asking how can I set a variable equal to the output from a command in GRUB2?

I am interested to pass the output of date command to a variable. Moreover, how can I retain only the time or hour in that variable?

2 Answers 2

1

I found the answer myself. Instead to use date command, I can use insmod datehook module and like this the following environment variables will be accessible: $YEAR, $MONTH, $DAY, $HOUR, $MINUTE, $SECOND, $WEEKDAY.

Example: https://askubuntu.com/a/323516/147044

0

You need Command Substitution:

now=$(date)
6
  • 4
    This working in bash, but not when I am using the grub interpreter. Commented Jul 23, 2013 at 18:08
  • grub's shell is much more minimal than bash. See this bug about capturing command output.
    – Josh McGee
    Commented Jul 23, 2013 at 19:07
  • I know what it is... Hence my question Commented Jul 23, 2013 at 19:14
  • 3
    if you'll read the link i gave you, there are no plans to include this capability in grub's shell. hence my link to it.
    – Josh McGee
    Commented Jul 23, 2013 at 19:21
  • Ok, you should bring that idea as an answer and if no others answers will appear, I will accept it... but not this answer that is referring at bash. Commented Jul 23, 2013 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .