28年的蝌蚪啃蜡 2022-11-09 01:35 采纳率: 0%
浏览 156
已结题

shell编程实验报告报错,elif 附近的语法错误

今天用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")
  • 写回答

8条回答 默认 最新

  • X-道至简 2022-11-09 07:31
    关注

    69行和107行 的引号不对 是中文的吧。 改下试试 估计还有其它错误

    评论

报告相同问题?

问题事件

  • 系统已结题 11月17日
  • 修改了问题 11月9日
  • 赞助了问题酬金15元 11月9日
  • 创建了问题 11月9日

悬赏问题

  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?