今天用Linux的shell语言写模拟考勤系统时遇到如下错误
[root@master ~]# chmod +x testshell
[root@master ~]# ./testshell
./testshell:行70: 未预期的符号 `elif' 附近有语法错误
./testshell:行70: ` elif test "$fpassword" != "$password"'
将所有代码都检查了一遍发现并无问题,一开始不知道是不是Tab键和空格混用导致的错误,但重新敲还是这样。
附上全部代码:
#! /bin/bash
#filename:shelltest
exsig=0
while true; do
echo ""
echo "---欢迎使用本系统:---"
echo " 1.上班签到"
echo " 2.下班签出"
echo " 3.考勤信息查询"
echo " 4.退出系统"
echo "----------------------"
echo ""
echo "请输入你的选项:"
read choice
case $choice in
1)echo "请输入你的名字:"
read name
echo "请输入你的密码:"
read password
if test-r/home/user/userinfo.dat
then
while read fname fpassword
do
echo "$fname"
echo "$fpassword"
if test "$fname" = "$name"
then
break
fi
done < /home/user/userinfo.dat
else
echo System Error:userinfo.dat does not exist!
fi
if test "$fname”" != "$nane"
then
echo "不存在该用户!"
elif test "$fpassword" != "$password"
then
echo "密码不正确!"
else
hour=`date +%H`
if test "$hour" -gt 8
then
echo "你迟到了!"
echo "$name 上班迟到---日期:'date'" >> /home/user/check.dat
else
echo "早上好,$name!”
fi
fi
;;
2)echo "请输入你的名字:"
read name
echo "请输入你的密码:"
read password
if test-r/home/user/userinfo.dat
then
while read fname fpassword
do
if test "$fname" = "$name"
then
break
fi
done < /home/user/userinfo.dat
else
echo System Error: userinfo.dat does not exist!
fi
if test "$fname" != "$name"
then
echo ”不存在该用户!"
elif test "$fpassword"!= "$password"
then
echo "密码不正确!"
else
hour='date +%H'
if test "$hour"-lt 18
then
echo "你早退了!"
echo "$nane 下班早退---日期:'date' ">> /home/user/check.dat
else
echo "再见,$name!"
fi
fi
;;
3)echo "请输入你的名字:"
read name
echo "请输入你的密码:"
read password
if test-r/home/user/userinfo.dat
then
while read fnane fpassword
do
if test "$fname" = "$name"
then
fi
done < /home/user/userinfo.dat
else
echo System Error:userinfo.dat does not exist!
fi
if test "$fname" != "$name"
then
echo "不存在该用户!"
elif test "$fpassword" !="$password"
then
echo "密码不正确!"
else
echo "你的记录:"
echo ”---------"
fi
;;
4)echo "欢迎你的使用,再见!"
exsig=1
;;
*)echo "请输入合法的选项!"
;;
esac
if test "$exsig" = "1"
then
break
fi
done
另外,每次输入进入testshell时
```bash
vi testshell
都会先出现这个窗口,难不成和这个有关系吗
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/155601169766117.jpg "#left")