【问题标题】:syntax error: unexpected end of file in bash error语法错误:bash 错误中的文件意外结尾
【发布时间】:2014-12-24 20:51:36
【问题描述】:

我收到以下错误:

语法错误:文件意外结束。

代码如下:

#!/bin/bash

tput clear
tput bold
echo Hello, what is your name?
read Lol
sleep 2
echo HI $Lol
sleep 3
echo "SoftManager is a software manager and software updater"
sleep 3
echo "Copyright (C) 2014 Winston L"
sleep 2
echo "What would you like to do?"
echo "1. Update"
echo "2. Install/uninstall software"
echo "3. Other awesome tools"
read Pie

if [[ $Pie == 1 ]]; then
    echo "What distribution are you running?"
    echo "1. Debian, 2. Fedora 3. Arch"
    read Interesting
    if [[ $Interesting == 1 ]]; then
        sudo apt-get update -y
        sudo apt-get upgrade -y -qq -f
    elif [[ $Interesting == 2 ]]; then
        sudo yum install fedora-upgrade
        sudo fedora-upgrade
    else
        sudo pacman-mirrors -g
        sudo yaourt -Syua
        sudo pacman -Syyu
        sudo yaourt -Syua
    fi

elif [[ $Pie == 2 ]]; then
    echo "Would you like to install or uninstall software?"
    echo "1. install, 2. uninstall"
    read Hai

    if [[ $Hai == 2 ]]; then
        echo "What distribution are you running?"
        echo "1. Debian, 2. Fedora, 3. Arch"
        read Ice
        if [[ $Ice == 1 ]]; then
            echo "Please type the package you want to uninstall"
            read Unin
            sudo apt-get remove $Unin
        elif [[ $Ice == 2 ]]; then
            echo "Please type the package you want to uninstall"
            read Pop
            sudo yum remove $Pop
        else 
            echo "Please type the package you want to uninstall"
            read Ins
            sudo pacman -Rns $Ins
        fi

    elif [[ $Hai == 1 ]]; then
        echo "What distribution are you running?"
        echo "1. Debian, 2. Fedora, 3. Arch"
        read Cake
        if [[ $Cake == 1 ]]; then
            echo "Please type the package you want to install"
            read Igloo
            sudo apt-get install $Igloo
        elif [[ $Cake == 2 ]]; then
            echo "Please type the package you want to install"
            read Test
            yum install $Test
        else 
            echo "Please type the package you want to install"
            read Amaze
            yaourt $Amaze
        fi
    else 
          echo "Invalid option"
    fi      
else
    echo "Please choose one of these tools:"
    echo "1. Download file from Internet"
    echo "2. Add ppa"
    read Pirate
    if [[ $Pirate == 1 ]]; then
        echo "Please type the link, note that the file will be downloaded to where this script is"
        read Haha
        wget $Haha
    elif [[ $Pirate == 2 ]]; then
        echo "Please type the ppa:"
        read Randomis   
        sudo add-apt repository $Randomis
    else 
        echo "Invalid option"   
fi

【问题讨论】:

    标签: bash syntax


    【解决方案1】:

    结尾处缺少fi

    if [[ $Pie == 1 ]]; then
        # ...
    elif [[ $Pie == 2 ]]; then
        # ...
    else
        # ...
        if [[ $Pirate == 1 ]]; then
            # ...
        elif [[ $Pirate == 2 ]]; then
            #...
        else
            echo "Invalid option"
        # MISSING "fi"
    fi
    

    【讨论】:

      【解决方案2】:

      两件事:

      • 您在最后一个 else 子句的末尾缺少一个结束 fi
      • 您想将-eq 用于数字等于而不是===== 用于字符串。而-eq 用于数字比较。

      【讨论】:

        猜你喜欢
        • 2011-09-16
        • 2018-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-22
        相关资源
        最近更新 更多