In this article, we will see how to use “dialog” command to create a user-friendly interface for your bash scripts. dialog command helps us build text-based front-end windows. Still confused about what i am talking about exactly? The below image makes it all clear. We are gonna learn how to make such windows (there are various kinds of them).

I am gonna show you how to create such windows and how to integrate them into your bash script. Following are various different types of dialog box:
- >> calendar, checklist, form, fselect, gauge, infobox, inputbox, inputmenu, menu, msgbox, password, pause, radiolist, tailbox, tailboxbg, textbox, timebox, and yesno.
we are gonna cover some of the basic one’s.
Tip Tip : Mostly the random numbers which you see behind an dialog command are nothing but height and width. heh. ![]()
msgbox
The image at top of this post is an pure example of an “message box”
--msgbox "Hello, this is the message box text." 10 30
yesno
--yesno "Are you gonna press yes or not ?" 5 40
case $? in
0)
echo "Yes! You pressed Yes";;
1)
echo "No! You pressed No";;
255)
echo "Esc? Thats cool with me";;
esac
That would look something like :

Inputbox
Inputbox option is used to read input from user. It mostly prints out instantly upon submission to the stderr. Following is an sample bash script which probably redirects the stderr to an temp file and store the input.
--inputbox "Enter your name..." 10 40 2>/tmp/dialog
case $? in
0)
echo "Welcome `cat /tmp/dialog`";;
1)
echo "Cancel was pressed";;
esac
That’s how it shall look like:

Textbox
Textbox option is used to show contents of an file into an window. User can even scroll through and use various keys like pageup and pagedown. User can even search by pressing /
--textbox file.txt 20 50
It will display contents of file.txt in following manner:

Checklist
--checklist "Select the OS you use.." 20 40 3 \
"CentOS" "" on \
"Ubuntu" "" off \
"Fedora" "" off 2>/tmp/dialog
case $? in
0)
echo "Glad to know you use `cat /tmp/dialog`";;
1)
echo "Cancel was pressed";;
esac
In above example, 20 is height, 40 is the width and 3 is total number of choices.
Below is image of how this should look like:

Radiolist
Just replace –checklist in checklist example script to –radiolist. Rest is all the same
Guage
Guage window can be used to show a progress bar showing the progress of your program. Lets look at an simple example.
for i in {1..100}
do
echo $i
sleep 1
done
echo;
} | dialog --guage "Loading www.anildewani.com ..." 7 70 0
The dialog commands gets input from code between parenthesis. That’s the tricky part. ![]()
Here’s the screenshot of how it looks like:

Will update with more when time allows me
