第 42 行:语法错误:文件意外结束

第 42 行:语法错误:文件意外结束

我正在尝试制作一个简单的安全登录,提示用户输入一个名称,然后如果该名称与其中一个 if 语句匹配,它将继续让他们输入密码,然后登录su。它会反弹

第 42 行:语法错误:意外的文件结尾

在第一个用户输入名称提示中输入数据后。

#!/bin/bash

clear

read -p "Please enter your name:" i

if [ "$i" = "Tyler" ]
then
   read -p "Hello Tyler. Please enter you password now:" b

   if [ "$b" = "1234567890" ]
   then
      echo "You really are Tyler!! Prove it again!!"
      su

   else
      echo "WRONG ANSWER!!"

      if [ "$i" = "LouRae" ]
      then
         read -p "Hey there beautiful. Please enter you password now:" b

         if [ "$b" = "123456789" ]
         then
            echo "You really are LouRae!! Prove it again!!"
            su
         else
            echo "WRONG ANSWER!!!"

            if [ "$i" = "Emma" ]
            then
               read -p "Hello Emma. Please enter you password now:" b

               if [ "$b" = "12345678" ]
               then
                  echo "You really are Emma!! Prove it again!!"
                  su
               else
                  echo "WRONG ANSWER!!!"

               fi

答案1

您需要if以以下语句结尾fi

if [ "$i" = "Tyler" ]
    then
        read -p "Hello Tyler. Please enter you password now:" b         

            if [ "$b" = "1234567890" ]
                    then
                        echo "You really are Tyler!! Prove it again!!"
                        su

            else
                echo "WRONG ANSWER!!"
            fi
fi

答案2

更新脚本(有效)

#!/bin/bash

clear

read -p "Please enter your name:" i

if [ "$i" = "Tyler" ]
    then
        read -p "Hello Tyler. Please enter you password now:" b         

            if [ "$b" = "1234567890" ]
                    then
                        echo "You really are Tyler!! Prove it again!!"
                        su

            else
                echo "WRONG ANSWER!!"
        fi
fi

if [ "$i" = "LouRae" ]
    then 
        read -p "Hey there beautiful. Please enter you password now:" b

            if [ "$b" = "123456789" ]
                    then
                        echo "You really are LouRae!! Prove it again!!"
                        su
            else
                        echo "WRONG ANSWER!!!"
        fi
fi

if [ "$i" = "Emma" ]
    then
        read -p "Hello Emma. Please enter you password now:" b

            if [ "$b" = "12345678" ]
                    then
                        echo "You really are Emma!! Prove it again!!"
                        su
            else
                        echo "WRONG ANSWER!!!"
        fi
fi

相关内容