最近在做Linux的shell编程实验报告,出现了未预期的符号错误
如下代码显示
```bash
[root@master ~]# chmod +x testshell
[root@master ~]# ./testshell
./testshell:行70: 未预期的符号 `elif' 附近有语法错误
```bash
已经核对过了,应该是没敲错的,然后不知道是不是Tab键和空格键混淆导致位置偏移的情况。
还有就是,有一个小问题,每当我进入了该testshell文件之后
[root@master ~]# vi testshell
都会先出现这个页面
不清楚是什么原因。
附上全部代码:
#! /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