help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String functions


From: Jordan Uggla
Subject: Re: String functions
Date: Sun, 1 Apr 2012 23:06:27 -0700

On Wed, Mar 28, 2012 at 10:17 AM, Arbiel Perlacremaz
<address@hidden> wrote:
> Hi
>
> Does Grub have functions for manipulating strings. For instance,
>
> the search function returns a partition string. Is it possible to extract
> the device where this partition sits ?

This command will strip the partition portion of a device like
"hd0,msdos1" (in this example, taken from the variable $root) leaving
only the drive portion, "hd0" by grabbing everything before the ','
and will store the result in the variable $drive:

regexp --set=drive "(.*)," "$root"

This should work for most devices, including some types you might not
have thought about like "ata0,gpt1" which you would get from a pata
device (with a GPT label) when grub is using native drivers rather
than depending on calls to the firmware.

> looking for files in a directory, is it possible to derive files names in
> substituting a substring with another value ?

It depends on what exactly you're trying to do, hopefully this example
will help you some but you'll probably need to explain in more detail
what you're trying to do:

file_begin="background_number_"
file_end=".png"

for i in 1 2 3; do
  echo "${file_begin}${i}${file_end}"
done

# Will output:
# background_number_1.png
# background_number_2.png
# background_number_3.png

>
> Thanks in advance for any piece on information.

You're welcome.

-- 
Jordan Uggla (Jordan_U on irc.freenode.net)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]