Tuesday, 11 June 2013

dialog boxes In BASH

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:
# 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
   


TextBox: 
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. 
 

11 comments:

  1. Very nice post. Its is so informative and useful for students. Thanks for sharing this nice post..
    Linux Training on RHEL 7

    ReplyDelete
  2. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    Java training in Chennai | Java training institute in Chennai | Java course in Chennai

    Java training in Bangalore | Java training institute in Bangalore | Java course in Bangalore

    Java online training | Java Certification Online course-Gangboard

    Java training in Pune

    ReplyDelete
  3. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    python interview questions and answers
    python tutorials
    python course institute in electronic city

    ReplyDelete
  4. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Devops Training courses
    Devops Training in Bangalore
    Best Devops Training in pune
    Devops interview questions and answers

    ReplyDelete
  5. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you.
    Keep update more information..


    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium interview questions and answers

    ReplyDelete
  6. Best devops online training institute.they are giving complete core subject of devops.and i am very thankfull for this institute.

    ReplyDelete
  7. Thanks for sharing such an useful and helpful post.
    Linux course in Pune

    ReplyDelete