Debian Codegraph @

dialog.sh

raw symbols SCIP
1 #!/bin/bash
2 # dialog.sh: Using 'gdialog' widgets.
3
4 # Must have 'gdialog' installed on your system to run this script.
5 # Or, you can replace all instance of 'gdialog' below with 'kdialog' ...
6 # Version 1.1 (corrected 04/05/05)
7
8 # This script was inspired by the following article.
9 # "Scripting for X Productivity," by Marco Fioretti,
10 # LINUX JOURNAL, Issue 113, September 2003, pp. 86-9.
11 # Thank you, all you good people at LJ.
12
13
14 # Input error in dialog box.
15 E_INPUT=85
16 # Dimensions of display, input widgets.
17 HEIGHT=50
18 WIDTH=60
19
20 # Output file name (constructed out of script name).
21 OUTFILE=$0.output
22
23 # Display this script in a text widget.
24 gdialog --title "Displaying: $0" --textbox $0 $HEIGHT $WIDTH
25
26
27
28 # Now, we'll try saving input in a file.
29 echo -n "VARIABLE=" > $OUTFILE
30 gdialog --title "User Input" --inputbox "Enter variable, please:" \
31 $HEIGHT $WIDTH 2>> $OUTFILE
32
33
34 if [ "$?" -eq 0 ]
35 # It's good practice to check exit status.
36 then
37 echo "Executed \"dialog box\" without errors."
38 else
39 echo "Error(s) in \"dialog box\" execution."
40 # Or, clicked on "Cancel", instead of "OK" button.
41 rm $OUTFILE
42 exit $E_INPUT
43 fi
44
45
46
47 # Now, we'll retrieve and display the saved variable.
48 . $OUTFILE # 'Source' the saved file.
49 echo "The variable input in the \"input box\" was: "$VARIABLE""
50
51
52 rm $OUTFILE # Clean up by removing the temp file.
53 # Some applications may need to retain this file.
54
55 exit $?
56
57 # Exercise: Rewrite this script using the 'zenity' widget set.