先上脚本:
$vim checkscore.sh
# 进入vim编辑器在命令模式下;
#“a/i”键分别是在光标后面一位和光标当前位置切换到输入模式;
#“o”键是在光标的下面再创建一个空行。
#!/bin/bash
read -p "Please enter the num of your classmetas:" NUMS
TIMES=0
while [ $TIMES -lt $NUMS ]
do
read -p "Please enter the name:" NAME
read -p "Please enter the score(0-100):" SCORE
case "$SCORE" in
[0-9]*)
if [ $SCORE -ge 100 ]; then
echo "Score cannot exceed 100! $NAME make tricks!" >> record.txt
elif [ $SCORE -ge 60 ] && [ $SCORE -le 100 ]; then
echo "$NAME Pass, the score is $SCORE." >> record.txt
else
echo "$NAME Fail, keep the score secret, in case his father beat this poor dog." >> record.txt
fi
let TIMES++
;;
*)
echo "Please enter NUMBERS!"
exac
done
#在命令模式下,按“:“键进入末行模式。
#:w--保存;
#:q--退出;
#:q!--强制退出;
#:wq!--强制保存退出;
#:set nu--显示行号;
#:set nonu--不显示行号;
#:命令--执行该命令;
#:整数--跳转到该行.
$bash checkscore.sh
整数比较运算符
-eq —— 是否等于
-ne —— 是否不等于
-gt —— 是否大于
-lt —— 是否小于
-le —— 是否等于或小于
-ge —— 是否大于或等于
read:用来读取用户输入信息的命令,能够把接收到的用户输入信息赋值给后面的指定变量。-p用于向用户显示一定的提示信息。
let TIMES++:每次循环到此时都会让TIMES变量内数值加1。
网友评论