dialog --msgbox “Hello World” 9 18
The principal types of dialogs you can create are described in the following table:
Type | Option Used to Create Type | Meaning |
---|---|---|
Check boxes | –checklist | Allows you to display a list of items, each of which may be individually selected |
Info boxes | –infobox | A simple display in a box that returns immediately, without clearing the screen |
Input boxes | –inputbox | Allows the user to type in text |
Menu boxes | –menu | Allow the user to pick a single item from a list |
Message boxes | –msgbox | Displays a message to users, with an OK button when they wish to continue |
Radio selection boxes | –radiolist | Allows the user to select an option from a list |
Text boxes | –textbox | Allows you to display a file in a scroll-ing box |
Yes/No boxes | –yesno | Allows you to ask a question, to which the user can select either yes or no |
We list the different parameters required for each type in the following table:
Dialog Type | Parameters |
---|---|
–checklist | text height width list-height [tag text status] … |
–infobox | text height width |
–inputbox | text height width [initial string] |
–menu | text height width menu-height [tag item ] … |
–msgbox | text height width |
–radiolist | text height width list-height [tag text status] … |
–textbox | filename height width |
–yesno | text height width |
//
In this example, you create a checklist-type box, with a title Check me and the instructions Pick Numbers . The checklist box will be 15 characters high by 25 characters wide, and each option will occupy 3 characters of height. Last, but not least, you list the options to be displayed, along with a default on/off selection.
xxx@xxx-pc ~ $ dialog --title "Check me" --checklist "Pick Numbers" 15 25 3 1 "one" "off" 2 "two" "on" 3 "three" "off"c
The options look a little tricky, but all you have to remember is that each menu item has three values:
❑ Bullet number
❑ Text
❑ Status
check the environment variable $? , which you will recall is the exit status of the previous command.
all dialog type :
–title , which allows you to specify a title for the box,
–clear , which is used on its own for clearing the screen.
small gui from shell .GNOME can use gdialog .
#!/bin/sh
# Ask some questions and collect the answer
gdialog --title "Questionnaire" --msgbox "Welcome to my simple survey" 9 18
gdialog --title "Confirm" --yesno "Are you willing to take part?" 9 18
if [ $? != 0 ]; then
gdialog --infobox "Thank you anyway" 5 20
sleep 2
gdialog --clear
exit 0
fi
gdialog --title "Questionnaire" --inputbox "Please enter your name" 9 30 2>_1.txt
Q_NAME=$(cat _1.txt)
gdialog --menu "$Q_NAME, what music do you like best?" 15 30 4 1 "Classical" 2 "Jazz" 3 "Country" 4 "Other" 2>_1.txt
Q_MUSIC=$(cat _1.txt)
if [ "$Q_MUSIC" = "1" ]; then
gdialog --title "Likes Classical" --msgbox "Good choice!" 12 25
else
gdialog --title "Doesn't like Classical" --msgbox "Shame" 12 25
fi
sleep 2
gdialog --clear
exit 0