【问题标题】:Shell Script Unexpected End of FileShell 脚本文件意外结束
【发布时间】:2020-04-14 22:33:30
【问题描述】:

这是如何工作的? 对不起,我是初学者,找不到任何教程或网站来解释这些事情。 当你知道如何找到这个时请告诉我,我真的很感激。

#!/bin/bash
cd Blur
clear


echo "Rangcheck" 

if grep -w $name ./rangs/exo_users.txt; 
then
    echo "Blur" > "./status/rang.txt"
    ./menu.sh
else
if grep -w $name ./rangs/police_users.txt; 
then
    echo "Police" > "./status/rang.txt"
    ./menu.sh
else
if grep -w $name ./rangs/bank_users.txt; 
then
    echo "Bank" > "./status/rang.txt"
    ./menu.sh
else
if grep -w $name ./rangs/fly_users.txt; 
then
    echo "Fly" > "./status/rang.txt"
    ./menu.sh
else
if grep -w $name ./rangs/userlist.txt; 
then
    echo "User" > "./status/rang.txt"
    ./menu.sh

【问题讨论】:

    标签: shell


    【解决方案1】:

    使用elif,而不是else..if,并确保以fi 终止if 表达式:

    #!/bin/bash
    cd Blur
    clear
    
    
    echo "Rangcheck" 
    
    if grep -w "$name" ./rangs/exo_users.txt; 
    then
        echo "Blur" > "./status/rang.txt"
        ./menu.sh
    elif grep -w "$name" ./rangs/police_users.txt; 
    then
        echo "Police" > "./status/rang.txt"
        ./menu.sh
    elif grep -w "$name" ./rangs/bank_users.txt; 
    then
        echo "Bank" > "./status/rang.txt"
        ./menu.sh
    fi
    

    还可以尝试shellcheck.net,您可以在其中粘贴脚本以自动指出此类问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多