-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_flag.sh
executable file
·75 lines (67 loc) · 1.21 KB
/
debug_flag.sh
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
#!/bin/bash
declare -i RES=1000
declare -i NUM=1000
declare -i NUMS
touch temp.txt
INFO="temp.txt"
while getopts "o:n:d" opt; do
case $opt in
o)
case $OPTARG in
"+"|"-"|"*"|"/")
OP=$OPTARG
;;
*)
echo "Incorrect Operation"
;;
esac
;;
n)
NUMS+=("$OPTARG")
;;
d)
echo "USER: `whoami`" >> $INFO
echo "SCRIPT: $0" >> $INFO
echo "OPERATION: $OP" >> $INFO
echo "NUMBERS: ${NUMS[*]}" >> $INFO
;;
esac
done
case $OP in
"+"|"-")
RES=0
;;
"*"|"/")
RES=1
;;
*)
RES=500
;;
esac
RES=${NUMS[0]}
flag=0
for NUM in "${NUMS[@]}"; do
if [ $flag -eq "0" ]; then
flag=1
continue
fi
case $OP in
"+")
let "RES+=NUM"
;;
"-")
let "RES-=NUM"
;;
"/")
let "RES/=NUM"
;;
"*")
let "RES*=NUM"
;;
esac
done
echo "RESULT: $RES"
if [ -f $INFO ]; then
cat $INFO
fi
rm temp.txt