LDP/LDP/guide/docbook/abs-guide/dialog.sh

58 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2003-08-25 14:49:11 +00:00
#!/bin/bash
# dialog.sh: Using 'gdialog' widgets.
2008-03-13 13:24:45 +00:00
2003-08-25 14:49:11 +00:00
# Must have 'gdialog' installed on your system to run this script.
2008-03-13 13:24:45 +00:00
# Or, you can replace all instance of 'gdialog' below with 'kdialog' ...
2005-05-08 20:09:31 +00:00
# Version 1.1 (corrected 04/05/05)
2003-08-25 14:49:11 +00:00
# This script was inspired by the following article.
# "Scripting for X Productivity," by Marco Fioretti,
# LINUX JOURNAL, Issue 113, September 2003, pp. 86-9.
# Thank you, all you good people at LJ.
2003-11-03 16:25:16 +00:00
# Input error in dialog box.
2014-03-07 02:24:29 +00:00
E_INPUT=85
2003-08-25 14:49:11 +00:00
# Dimensions of display, input widgets.
HEIGHT=50
WIDTH=60
# Output file name (constructed out of script name).
OUTFILE=$0.output
# Display this script in a text widget.
gdialog --title "Displaying: $0" --textbox $0 $HEIGHT $WIDTH
2005-05-08 20:09:31 +00:00
2003-08-25 14:49:11 +00:00
# Now, we'll try saving input in a file.
2005-05-08 20:09:31 +00:00
echo -n "VARIABLE=" > $OUTFILE
2003-08-25 14:49:11 +00:00
gdialog --title "User Input" --inputbox "Enter variable, please:" \
$HEIGHT $WIDTH 2>> $OUTFILE
if [ "$?" -eq 0 ]
# It's good practice to check exit status.
then
echo "Executed \"dialog box\" without errors."
else
echo "Error(s) in \"dialog box\" execution."
# Or, clicked on "Cancel", instead of "OK" button.
rm $OUTFILE
exit $E_INPUT
fi
# Now, we'll retrieve and display the saved variable.
. $OUTFILE # 'Source' the saved file.
echo "The variable input in the \"input box\" was: "$VARIABLE""
2005-05-08 20:09:31 +00:00
2003-08-25 14:49:11 +00:00
rm $OUTFILE # Clean up by removing the temp file.
# Some applications may need to retain this file.
2005-05-08 20:09:31 +00:00
exit $?
2008-03-13 13:24:45 +00:00
# Exercise: Rewrite this script using the 'zenity' widget set.