[arch-releng] [PATCH 3/3] Prompt user to pick a bootloader in interactive_select_packages and select the proper package for installation.

C Anthony Risinger anthony at extof.me
Mon Feb 21 22:34:56 EST 2011


On Mon, Feb 21, 2011 at 7:59 PM, Matthew Gyurgyik <pyther at pyther.net> wrote:
>
> I know we (Dieter and I) chatted about using $supported_bootloaders for
> ask_option but I couldn't figure out any useful way to provide additional
> information next to the bootloader without creating an array like this.
> supported_bootloaders=(syslinux "some info" grub "some more info") which
> would seem to defeat the purpose of supported_bootloader.

i'm not sure 100% what all you have going on here, but i use a lot of
heredocs in these bash "data table" situations:

-----------------------------------------------------------------------
#!/bin/bash

key=none
val=none

echo -e "START\n[key] $key" "[val] $val\n"

process_opts () {
    while IFS="=" read k v; do
        # can't use key/val directly because
        # last loop (EOF) will reset them!
        key="$k" val="$v"
        echo "[key] $key" "[val] $val"
    done
}

process_opts <<EOF
grub=A nice long explantaion about grub :-)
syslinux=And that's why we are teh awesome!
insert_here=I'm just along for the ride
EOF

echo -e "\nEND\n[key] $key" "[val] $val"
-----------------------------------------------------------------------

you feed the heredoc into a function, which then processes the data as
stdin.  as IFS controls word splitting, and rather then
setting/restoring it, we augment it for the specific calls we need.
in this case i chose an `=`, but it could be anything.  but default it
uses spaces/tabs so you'll prob want to change it.

another approach with the same effect, but possibly more useful in
your case as the table is persistent via variable:

-----------------------------------------------------------------------
#!/bin/bash

key=none
val=none

opts="grub=A nice long explantaion about grub :-)
syslinux=And that's why we are teh awesome!
insert_here=I'm just along for the ride"

echo -e "START\n[key] $key" "[val] $val\n"

while IFS="=" read k v; do
    key="$k" val="$v"
    echo "[key] $key" "[val] $val"
done <<<"$opts"

echo -e "\nEND\n[key] $key" "[val] $val"
-----------------------------------------------------------------------

the only downside to the above is that `" ... "` means you have to
worry about more escaping.  also note the quotes -- `<<<"$opts"` --
they are critical! else the newlines become spaces.

personally i like heredocs because they are made for exactly this use,
and look clean.  some other info ...

store heredoc in variable (best of both examples, at cost of `cat`
call and subshell):

opts=$(cat <<EOF
...
EOF)

EVERYTHING in a heredoc is literal (variables/slashes/etc) [note the
preceding `\`; quotes work too]

process_opts <<\EOF
...
EOF

suppress leading tabs (so you can indent for readability) [note the
preceding `-`]

process_opts <<-EOF
...
EOF

EOF is just what i use; it can be any string.

http://tldp.org/LDP/abs/html/here-docs.html

C Anthony


More information about the arch-releng mailing list