while do done 语法错误

while do done syntax error

我正在编写一个脚本来帮助其他人使用 apt 包管理器。在我将它移到闪存驱动器并将其放在我的另一台计算机上之前,该脚本运行良好。 我无法摆脱的错误是:

/bin/az.sh: line 57: syntax error near unexpected token `done'

/bin/az.sh: line 57: `done;'

这是脚本中的代码:

#!/bin/bash
procid=$(lsof /var/lib/dpkg/lock > /var/log/az1; sed '1d' /var/log/az1 | awk '{print }' )
#kill any process using apt manager 
if [ "`lsof /var/lib/dpkg/lock`" = "" ]; then
    echo "no conflicts"
else
    figlet killed old process
    kill -9 $procid 
fi;
figlet updating package lists
#apt-get update > /var/log/azupdatelog
while [ $input != "q" ]; do
    echo "(1) Find package by name"
    echo "(2) Find package by description"
    echo "(3) Install package"
    echo "(4) Remove package"
    echo "(5) Fix Dependencies"
    echo "(6) Perform an upgade"
    echo "(q) Quit "
    read input
    if [ $input = "1" ]; then 
        echo "enter package name"
        read package
        apt-cache show $package
    elif [ $input = "2" ]; then
        echo "enter search keyword"
        read package
        apt-cache search $package
    elif [ $input = "3" ]; then
        apt-get build-dep $package
        apt-get install $package -y > /var/log/installlog
        exitstatus=$(echo $?)
        if [ $exitstatus = "0" ]; then
            figlet Installation Succesful
        elif [ $exitstatus = "1" ]; then
            figlet Failure check /var/log/installlog
            figlet check now?
            echo "y or n"
            read input2
                if [ $input2 = "y"]; then
                    cat /var/log/installlog
                fi;
    elif [ $input = "4" ]; then
        echo "enter package name"
        read package
        apt-get remove $package
    elif [ $input = "5" ]; then
        echo "enter package name"
        read package
        apt-get build-dep $package
    elif [ $input = "6" ]; then
        echo ""
        apt-get upgrade
    else
        echo "oops check your input"
    fi;
done

你的第35行elif [ $exitstatus = "1" ]; then没有对应的fi;

下次遇到此类错误时,请移除当前范围内的所有噪音:

while [ $input != "q" ]; do
    if [ $input = "1" ]; then   
    elif [ $input = "2" ]; then 
    elif [ $input = "3" ]; then 
        if [ $exitstatus = "0" ]; then #There is no corresponding fi;  
        elif [ $exitstatus = "1" ]; then   
                if [ $input2 = "y"]; then
                fi;
    elif [ $input = "4" ]; then 
    elif [ $input = "5" ]; then 
    elif [ $input = "6" ]; then
    else
    fi;
done

而且您会很快发现错误。