usr bin env bash Случайное число от до 10 NUMBER RANDOM 10 num_of_att

 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
#!/usr/bin/env bash
# Случайное число от 0 до 10
NUMBER=$(( $RANDOM % 10 ));
num_of_att=${1:-5}
echo "Let's play"
echo "You have $num_of_att attempts to guess the number 0-10"
for ((i = 0; i < num_of_att; i++))
do
read -p "Enter the number: " INPUT;
if expr match $INPUT "^[0-9]*$" &>/dev/null
then
# echo "$INPUT";
echo "random is $NUMBER"
check=INPUT-NUMBER
if ((check < 2 && check > -2 && check != 0))
then
echo "Hot"
elif ((check < 3 && check > -3 && check != 0))
then
echo "warm"
elif ((check == 0))
then
echo "BINGO!!!"
exit;
else echo "Far away"
fi
fi
done
echo "Game over :("
exit 0;