[opensuse] BASH - 'dialog' and oldie but a goodie
Scripters, I just stumbled across a bash dialog tool that I hadn't heard of before. It is similar to zenity in it's use but isn't a true 'gui' it's text based. Basically, it provides a simple way to present text based dialog windows for input/information/etc... from a script. For an example, just open an xterm and cut and paste: dialog --title "Message" --yesno "Are you having fun?" 6 25 Use of the return value is simple: dialog --title "Message" --yesno "Are you having fun?" 6 25; [[ $? -eq 0 ]] && echo "yes - I'm having fun" || echo "no - I'm not having fun" The article the example comes from is a 1994 Linux Journal article: http://www.linuxjournal.com/article/2807 "man dialog" gives the details. Just another tool to add to your toolbox... -- 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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David, I look forward to trying these out. We still write some interactive bash scripts for non-technical users, so I appreciate the options. Greg On Wed, Nov 17, 2010 at 7:22 AM, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-- Greg Freemyer Head of EDD Tape Extraction and Processing team Litigation Triage Solutions Specialist http://www.linkedin.com/in/gregfreemyer CNN/TruTV Aired Forensic Imaging Demo - http://insession.blogs.cnn.com/2010/03/23/how-computer-evidence-gets-retriev... The Norcross Group The Intersection of Evidence & Technology http://www.norcrossgroup.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 2010-11-17 David offered the following:
dialog --title "Message" --yesno "Are you having fun?" 6 25; [[ $? -eq 0 ]] && echo "yes - I'm having fun" || echo "no - I'm not having fun"
Another message to copy over to my "Rankinisms" box of useful tidbits. Actually, I knew about this from a long time ago, but had totally forgotten about it. Thanks, Richard -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday, 2010-11-17 at 12:04 -0500, Richard Creighton wrote:
Another message to copy over to my "Rankinisms" box of useful tidbits. Actually, I knew about this from a long time ago, but had totally forgotten about it.
Me too :-) - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAkzl3b8ACgkQtTMYHG2NR9XrdQCdEZj4Hg1W8oK9zyVS76DcHDdA nvgAnje/eK3FJXYbJre4KplTaNoNRbp2 =LJLt -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Another message to copy over to my "Rankinisms" box of useful tidbits. Actually, I knew about this from a long time ago, but had totally forgotten about it.
Me too :-)
i have never used it or seen it used. i am surprised about the fact that i cannot recollect ever using not even a single application or installer that makes use of this. it could be very useful with stuff like configure scripts,etc....it would make transition to linux easy for people who are used to installation gui wizards and/or drag and dropping on a mac. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 11/18/2010 11:40 PM, michael getachew wrote:
Another message to copy over to my "Rankinisms" box of useful tidbits. Actually, I knew about this from a long time ago, but had totally forgotten about it.
Me too :-)
i have never used it or seen it used. i am surprised about the fact that i cannot recollect ever using not even a single application or installer that makes use of this. it could be very useful with stuff like configure scripts,etc....it would make transition to linux easy for people who are used to installation gui wizards and/or drag and dropping on a mac.
Could someone post the antecedent to this note--or at least the meat of it--I can't find it. Thanx--doug -- Blessed are the peacemakers...for they shall be shot at from both sides. --A.M. Greeley -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 11/19/2010 3:03 PM, Doug wrote:
On 11/18/2010 11:40 PM, michael getachew wrote:
Another message to copy over to my "Rankinisms" box of useful tidbits. Actually, I knew about this from a long time ago, but had totally forgotten about it.
Me too :-)
i have never used it or seen it used. i am surprised about the fact that i cannot recollect ever using not even a single application or installer that makes use of this. it could be very useful with stuff like configure scripts,etc....it would make transition to linux easy for people who are used to installation gui wizards and/or drag and dropping on a mac.
Could someone post the antecedent to this note--or at least the meat of it--I can't find it. Thanx--doug
"it" is dialog ie: "cd /usr/src/linux ; make menuconfig" The ncurses menuing system to configure the linux kernel before compiling, is written in dialog. That's one example of it's use. -- bkw -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 11/19/2010 3:15 PM, Brian K. White wrote:
On 11/19/2010 3:03 PM, Doug wrote:
On 11/18/2010 11:40 PM, michael getachew wrote:
Another message to copy over to my "Rankinisms" box of useful tidbits. Actually, I knew about this from a long time ago, but had totally forgotten about it.
Me too :-)
i have never used it or seen it used. i am surprised about the fact that i cannot recollect ever using not even a single application or installer that makes use of this. it could be very useful with stuff like configure scripts,etc....it would make transition to linux easy for people who are used to installation gui wizards and/or drag and dropping on a mac.
Could someone post the antecedent to this note--or at least the meat of it--I can't find it. Thanx--doug
"it" is dialog
ie: "cd /usr/src/linux ; make menuconfig" The ncurses menuing system to configure the linux kernel before compiling, is written in dialog. That's one example of it's use.
By fluke chance I just encountered another in my normal work. http://www.inquisitor.ru/shots/live_live_single_test_menu_png.html Inquisitor is a live cd that you use to stress-test hardware to make sure everything is reliable, before relying on it. -- bkw -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 11/19/2010 02:45 PM, Brian K. White wrote:
"it" is dialog
ie: "cd /usr/src/linux ; make menuconfig" The ncurses menuing system to configure the linux kernel before compiling, is written in dialog. That's one example of it's use.
By fluke chance I just encountered another in my normal work. http://www.inquisitor.ru/shots/live_live_single_test_menu_png.html
Inquisitor is a live cd that you use to stress-test hardware to make sure everything is reliable, before relying on it.
Also, Stumbling around some more turned up the following list of scriptable text & X GUIs. All basically do the same thing, but the flexibility of some is better than the other. They are all worth a look depending on the project you have in front of you: dialog cdialog Xdialog gdialog kdialog zenity -- 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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Fri, 19 Nov 2010, David C. Rankin wrote:
Stumbling around some more turned up the following list of scriptable text & X GUIs. All basically do the same thing, but the flexibility of some is better than the other. They are all worth a look depending on the project you have in front of you:
dialog cdialog Xdialog gdialog kdialog zenity
And some are also "calling compatible", have a look at texconfig-dialog. IIRC: dialog, kdialog and gdialog have a common basic interface (e.g. the same "yesno" option). So you can often do a test for X ($DISPLAY or more reliably a specific test[1]), set a variable $DIALOG accordingly to "dialog" or e.g. "kdialog" and the just use $DIALOG --yesno "You want fries with that?" 5 30 (just tested the above with $DIALOG being dialog, kdialog and gdialog :) -dnh [1] I've a self-written "Xruns" that tests if X is actually running and not whether just "DISPLAY" is set. ==== Xruns.c ==== /* Copyleft (l) 2003-2010 David Haller <dnh@opensuse.org> compile with e.g.: gcc -O2 -lX11 -o Xruns Xruns.c gcc $CFLAGS -lX11 -o Xruns Xruns.c gcc $(rpm --eval '%{optflags}') -lX11 -o Xruns Xruns.c */ #include <unistd.h> #include <X11/Xlib.h> int main(int argc, char* argv[]) { Display* disp = NULL; if(argc > 2) { write(2, "Usage: Xruns [display]\n", 24); } else if(argc == 2) { disp = XOpenDisplay(argv[1]); } else { disp = XOpenDisplay(NULL); } if( disp != NULL ) { XCloseDisplay(disp); return 0; } return 1; } ==== I use it for several stuff, in above context, I'd use: if Xruns; then DIALOG="gdialog" else DIALOG="dialog" fi ... $DIALOG --yesno ... -- "Now, what was I doing before I so rudely interrupted myself?" -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 11/19/2010 08:00 PM, David Haller wrote:
And some are also "calling compatible", have a look at texconfig-dialog. IIRC: dialog, kdialog and gdialog have a common basic interface (e.g. the same "yesno" option). So you can often do a test for X ($DISPLAY or more reliably a specific test[1]), set a variable $DIALOG accordingly to "dialog" or e.g. "kdialog" and the just use
$DIALOG --yesno "You want fries with that?" 5 30
(just tested the above with $DIALOG being dialog, kdialog and gdialog :)
-dnh
[1] I've a self-written "Xruns" that tests if X is actually running and not whether just "DISPLAY" is set.
<snip> David, Thank you Sir! I had never looked at testing the display -- or anything X for that matter. Your program sparked the "let's see what else we can find to do with X" which led me to a great little 16 part X tutorial. This tutorial starts at the very, very basic level to window creation, and builds from there. I like it! I know you it is simple, but it's worth a look for those who have never written an X program and have any interest: http://xopendisplay.hilltopia.ca/2009/Jan/Xlib-tutorial-part-1----Beginnings... You can grab all the sources with with following two command lines: for i in 2 3 16 $(seq 5 9); do wget http://xopendisplay.hilltopia.ca/xtut$i.c; done for i in $(seq 10 15); do wget http://xopendisplay.hilltopia.ca/xtut$i.tgz; done For the .c programs, I used the following script to ease the typing for compile: ---- #!/bin/bash [[ -n $1 ]] || { echo -e "\n usage: ${0##*/} # (to compile xtut#.c)\n"; exit 1; } gcc -o xtut$1 xtut$1.c -lX11 ---- Edit the first 3-4 .c files and set the window size to something reasonable so your window decorations don't get squashed. 200x100 works fine (original is 40x40). 10-15 will extract into their own directories with Makefiles included. All built without issue on my 11.0 laptop, so I know at least 11.0 on should work. -- 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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Wed, 17 Nov 2010, David C. Rankin wrote:
"man dialog" gives the details. Just another tool to add to your toolbox...
Have a look at the shell-script 'texconfig-dialog' for some advanced uses ;) -dnh -- "Y'know how they touted Java as this remarkable cross-platform solution for everything; Is that why applets usually crash my browser, regardless of which browser I'm using?" - Kevin Deighton in uk.net.web.authoring -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (8)
-
Brian K. White
-
Carlos E. R.
-
David C. Rankin
-
David Haller
-
Doug
-
Greg Freemyer
-
michael getachew
-
Richard Creighton