-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw.sh
More file actions
executable file
·56 lines (50 loc) · 952 Bytes
/
hw.sh
File metadata and controls
executable file
·56 lines (50 loc) · 952 Bytes
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
#!/bin/bash
set -x
ARGS=("$@")
NUM=10
HELP="
Usage: $0 num <int> (default is 10) | div (division) | multi (multiplication)
"
DIV=1
MULTI=1
function multi() {
for i in $(seq 1 "$NUM"); do
num1=$(($(shuf -i 1-99 -n 1) * 10))
num2=$(($(shuf -i 1-99 -n 1) * 10))
printf "%s) %s × %s = \n" "$i" "$num1" "$num2"
done
}
function div() {
for i in $(seq 1 "$NUM"); do
num1=$(shuf -i 1-19 -n 1)
num2=$(($(shuf -i 1-19 -n 1) * 10))
num3=$((num1 * num2 * 10))
printf "%s) %s ÷ %s = \n" "$i" "$num3" "$num2"
done
}
if [ ${#ARGS[@]} -eq 0 ]; then
printf "%s\n" "$HELP"
exit 1
else
for i in $(seq 1 ${#ARGS[@]}); do
if [[ "${ARGS[$i]}" == "num" ]]; then
NUM=$i
fi
if [[ "${ARGS[i]}" == "div" ]]; then
DIV=0
fi
if [[ "${ARGS[i]" == "multi" ]]; then
MULTI=0
fi
done
fi
if [ $MULTI -eq 0 ] || [ $DIV -eq 0 ]; then
if [ $MULTI -eq 0 ]; then
multi
fi
if [ $DIV -eq 0 ]; then
div
fi
else
printf "%s\n" "$HELP"
fi