Bash scripting: how to get the name of an element in a radio sheet using a dialog

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

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

I want that when the user selects an option and click OK, my scripts read the element name (and not the position number).

Maybe? Thanks!

+7
source share
1 answer

You can put the 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]}" 
+3
source

All Articles