Reputation: 4234
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!
Upvotes: 9
Views: 8125
Reputation: 121
man dialog
--stdout
Direct output to the standard output. This option is provided
for compatibility with Xdialog, however using it in portable
scripts is not recommended, since curses normally writes its
screen updates to the standard output. If you use this option,
dialog attempts to reopen the terminal so it can write to the
display. Depending on the platform and your environment, that
may fail.
therefore:
array=(Linux Solaris HPUX)
opt=$( dialog --stdout \
--backtitle "OS infomration" \
--radiolist "Select OS:" 10 40 3 \
1 "Linux 7.2" off \
2 "Solaris 9" on \
3 "HPUX 11i" off )
printf '\n\nYou chose: %s\n' "${array[var - 1]}"
Upvotes: 0
Reputation: 121
in Termux app >/dev/tty 2>&1
is not working, but 3>&1 1>&2 2>&3 3>&-
is working perfectly.
which means:
3>&1
opens a new file descriptor which points to stdout,1>&2
redirects stdout to stderr,2>&3
points stderr to stdout and3>&-
deletes the files descriptor3
after the command has been executed.
taken from:BASH: Dialog input in a variable
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 3>&1 1>&2 2>&3 3>&- )
printf '\n\nYou chose: %s\n' "${array[$var - 1]}"
Upvotes: 0
Reputation: 34934
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]}"
Upvotes: 4