bash scripting: how to get item name on a radiolist using dialog

Issue

I need to make a radiolist in bash script using dialog interface, for example if I have the following list:

dialog --backtitle "OS information" \
--radiolist "Select OS:" 10 40 3 \
 1 "Linux 7.2" off \
 2 "Solaris 9" on \
 3 "HPUX 11i" off

I need when the user chooses an option and presses "ok", my script could read the item’s name and not the item’s number.

It is possible?

Thanks!

Solution

You can put your expected results in an array:

array=(Linux Solaris HPUX)
var=$(dialog --backtitle "OS infomration" \
--radiolist "Select OS:" 10 40 3 \
 1 "Linux 7.2" off \
 2 "Solaris 9" on \
 3 "HPUX 11i" off >/dev/tty 2>&1 )

printf '\n\nYou chose: %s\n' "${array[var - 1]}"

Answered By – jordanm

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published