Use the time of the Linux system in the second 1-59 to guess the number game, the detailed code is as follows:
#!/bin/bash#author wangning#date 2017-7-15#qq 1198143315#email [email protected]##### ############################## #define color######################### #red = "\033[31m" green= "\033[32m" Yellow = "\033[33m" color= "\033[0m" ##################### #check number if conform 1-59############## ######### #check_number () {expr $num 1 + 1 &>/dev/nullif [ $? -ne 0 ];then echo -e "please input $red number $color" continue 1elif [ -z $num 1 ];then echo -e "$ Yellow can ' t be empty $color continue 2elif [ $num 1 -gt 59 ];then echo -e "$green can ' t great than 59 $color " continue 3fi}############################### #guess number ###### #################### # # # #guess_number () {if [ $num 1 -gt $num ];then echo -e " $yellow too big $color "elif [ $num 1 -eq $num ];then echo -e "$green congratulation, you have guessed ! $color" elif [ $num 1 -lt $num ];then echo -e "$green too small $color "fi}############################## #while circulation############################## # #main () {while truedonum=$ (date +%s) read -p "please input number 1-59:" num1check_numberguess_numberdone}main
This article is from the "Galloping Camel" blog, make sure to keep this source http://wn2100.blog.51cto.com/9915310/1947812
Guessing a digital shell script in Linux