语法错误:bash错误中意外的文件结束

时间:2014-12-24 20:51:37

标签: bash syntax

我收到以下错误:

  

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

以下是代码:

#!/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

2 个答案:

答案 0 :(得分:3)

结尾处缺少结束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

答案 1 :(得分:2)

两件事:

  • 您在最后一个fi条款的末尾错过了结束else
  • 您希望将-eq用于数字等于而不是=====用于字符串。而-eq用于数字比较。