-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile3
65 lines (53 loc) · 1.64 KB
/
file3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
#http://unstableme.blogspot.com/
#A sample application using UNIX/Linux dialog utility
#Auto-size with height and width = 0 of the dialog controls
file='/home/user9/work/conf.txt'
tempfile1=/tmp/dialog_1_$$
tempfile2=/tmp/dialog_2_$$
tempfile3=/tmp/dialog_3_$$
trap "rm -f $tempfile1 $tempfile2 $tempfile3" 0 1 2 5 15
_edit () {
items=$(awk -F\: '{print $1,$2}' $file)
dialog --title "A Sample Application" \
--menu "What you want to change :" 0 0 0 $items 2> $tempfile1
retval=$?
parameter=$(cat $tempfile1)
[ $retval -eq 0 ] && tochange=$parameter || return 1
val=$(awk -F\: -v x=$tochange '$1==x {print $2}' $file)
dialog --clear --title "Inputbox - Test" \
--inputbox "Enter new value($tochange)" 0 0 $val 2> $tempfile2
dialog --title "Confirmation" --yesno "Commit ?" 0 0
case $? in
0) newval=$(cat $tempfile2)
awk -v x=$tochange -v n=$newval '
BEGIN {FS=OFS=":"}$1==x {$2=n} {print}
' $file > $file.tmp
mv $file.tmp $file
;;
1|255) dialog --infobox "No Changes done" 0 0
sleep 2
;;
esac
dialog --textbox $file 0 0
}
_main () {
dialog --title "A sample application" \
--menu "Please choose an option:" 15 55 5 \
1 "View the config file" \
2 "Edit config file" \
3 "Exit from this menu" 2> $tempfile3
retv=$?
choice=$(cat $tempfile3)
[ $retv -eq 1 -o $retv -eq 255 ] && exit
case $choice in
1) dialog --textbox $file 0 0
_main
;;
2) _edit
_main ;;
3) exit ;;
esac
}
_main
done