-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFile.sh
More file actions
81 lines (75 loc) · 1.69 KB
/
Copy pathFile.sh
File metadata and controls
81 lines (75 loc) · 1.69 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
DIALOG_CANCEL=1
DIALOG_ESC=255
HEIGHT=0
WIDTH=0
#DIR used to keep initial directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
display_result() {
dialog --title "$1" \
--no-collapse \
--msgbox "$result" 0 0
}
#loops menu
while true; do
exec 3>&1
selection=$(dialog \
--backtitle "System Information" \
--title "$PWD" \
--clear \
--cancel-label "Exit" \
--menu "Please select:" $HEIGHT $WIDTH 4 \
"1" "Directory Selection" \
"2" "Run search" \
2>&1 1>&3)
exit_status=$?
exec 3>&-
case $exit_status in
$DIALOG_CANCEL)
clear
echo "Program terminated."
exit
;;
$DIALOG_ESC)
clear
echo "Program aborted." >&2
exit 1
;;
esac
#used to determine what to do based on user input
case $selection in
0 )
clear
echo "Program terminated."
;;
1 )
DIALOG=${DIALOG=dialog}
#sets user input of directory to variable FILE
FILE=`$DIALOG --stdout --title "Please choose a file" --fselect $PWD/ 14 48`
case $? in
0)
echo "\"$FILE\" chosen"
#changes current directory to FILE
cd $FILE
;;
1)
echo "Cancel pressed.";;
255)
echo "Box closed.";;
esac
;;
2 )
#sets permissions to files
chmod +rx trav.sh
chmod 777 trav.txt
#Runs trav.sh and outputs content to trav.txt
$DIR/trav.sh > $DIR/trav.txt
#creates total of directory
COUNT=$(gawk '{ sum += $3 }; END {print sum }' $DIR/trav.txt)
#adds sum to end of file
echo "total| " $COUNT >> $DIR/trav.txt
#outputs file through dialog text box
dialog --stdout --textbox $DIR/trav.txt 22 70
;;
esac
done