dialog - display dialog boxes from shell scripts.
'dialog' is a utility for building console-based 'front ends' in UNIX like operating systems.
In this brief tutorial I am mentioning the usage of few important basic controls available with this 'dialog' utility and later I have created a very simple front end application in UNIX bash scripting using dialog.
note-
first install dialog rpm via YUM
#yum install dialog* -y {In REDHAT}
To install 'dialog' on your ubuntu:
Radiolist box:
The 'radiolist' control box is same as 'checklist' box.
The 'inputbox' allows the user to enter a string.
TextBox:
'dialog' is a utility for building console-based 'front ends' in UNIX like operating systems.
In this brief tutorial I am mentioning the usage of few important basic controls available with this 'dialog' utility and later I have created a very simple front end application in UNIX bash scripting using dialog.
note-
first install dialog rpm via YUM
#yum install dialog* -y {In REDHAT}
To install 'dialog' on your ubuntu:
# apt-get install dialog {In Ubuntu}
Example-1
Checklist box:
A checklist box allows you to present a set of choices to the user
and the user can toggle each one on or off individually using the space
bar.
# dialog --checklist "Choose OS:" 15 40 5 1 Linux off 2 Solaris on 3 'HP UX' off 4 AIX off
Radiolist box:
The 'radiolist' control box is same as 'checklist' box.
# dialog --backtitle "OS infomration" --radiolist "Select OS:" 10 40 3 1 "Linux 7.2" off 2 "Solaris 9" on 3 "HPUX 11i" off
Inputbox:
The 'inputbox' allows the user to enter a string.
# dialog --title "Inputbox - Example" --backtitle "KR Network Cloud" --inputbox "Enter your favourite OS here" 8 50
Menu box:
# dialog --title "A dialog Menu Example" --menu "Please choose an option:" 15 55 5 1 "Add a record to DB" 2 "Delete a record from DB" 3 "Exit from this menu"
message-box:
# dialog --title "Example Dialog message box" --msgbox "\n Installation Completed on host7" 6 50
yesno box:
# dialog --title "Confirmation" --yesno "Want to quit?" 6 20
Infobox:
# dialog --infobox "Processing, please wait" 3 34 ; sleep 5
It is a simple file viewer
# dialog --textbox ~/work/conf.txt 10 4
Gauge Box#!/bin/sh #A gauge Box example with dialog ( c=10 while [ $c -ne 110 ] do echo $c echo "###" echo "$c %" echo "###" ((c+=10)) sleep 1 done ) | dialog --title "A Test Gauge With dialog" --gauge "Please wait ...." 10 60 0
Calendar Box: #!/bin/sh dat=$(dialog --stdout --title "My Calendar" \ --calendar "Select a date:" 0 0 25 12 2009) case $? in 0) echo "You have entered: $dat" ;; 1) echo "You have pressed Cancel" ;; 255) echo "Box closed" ;; esac
Time Box:
#!/bin/sh
tim=$(dialog --stdout --title "A TimeBox" \
--timebox "Set the time:" 0 0 10 13 59)
case $? in
0)
echo "You have set: $tim" ;;
1)
echo "You have pressed Cancel" ;;
255)
echo "Box closed" ;;
esac
Dear friends..
one of the great things about "dialog" is that there is also "xdialog". xdialog works just like dialog except it uses X to create the same dialog boxes as dialog but in GUI form. So, it is very easy to write a script that checks if X is running and then substitutes xdialog for dialog is it is true. Making your program both terminal and X compatible.