Mailinglist Archive: opensuse (963 mails)

< Previous Next >
Re: [opensuse] BASH - 'dialog' and oldie but a goodie
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Wed, 17 Nov 2010 09:22:26 -0600
  • Message-id: <4CE3F332.6080106@xxxxxxxxxxxxxxxxxx>
On 11/17/2010 07:48 AM, David C. Rankin wrote:
"man dialog" gives the details. Just another tool to add to your
toolbox...

Just a bit of follow-up. The '--stdout' option allows you to directly assign the
user response to a variable for many of the dialog types (menus, radioboxes,
select list, etc...) A couple of quick examples you can cut & past to test are:

Menu (returns menu text):

user_select=$(dialog --stdout --title "Most used linux command" \
--menu "Please choose from the following command line tools:" 15 55 5 \
"man" "To read man pages" \
"ls" "To display the contents of a directory" \
"vi" "Text editor" \
"mount" "To mount partitions" \
"su" "Super user permissions")

echo "user_select: $user_select"

RadioBox (returns exclusive index):

cpu=$(dialog --stdout --backtitle "CPU Selection" \
--radiolist "Select CPU type:" 11 40 4 \
1 i586 off \
2 i686 on \
3 x86_64 off \
4 IA64 off)

echo "cpu: $cpu"

Using an Array to hold select list options (returns all selected):

declare -a mvar

mvar=( $(dialog --stdout --checklist "Choose toppings:" 10 40 3 \
1 Cheese on \
2 "Tomato Sauce" on \
3 Anchovies off) )

for ((i=0;i<${#mvar[@]};i++)); do echo "mvar[$i]: ${mvar[$i]}"; done

I thought they were useful enough to pass along. Enjoy!

--
David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References