1
if [ $DISTRO = "REDHAT"] || [ $DISTRO = "FEDORA"]; then 
    if ! rpm -qa | grep -q glibc-static; then
        $BIN_ECHO -e " Package [glibc-static] not found. Installing.. "
        yum install glibc-static
    elif
        $BIN_ECHO -e " All required packages installed.. "
    fi
elif [ $DISTRO = "DEBIAN"]; then 
    if ! dpkg-query -l glibc; then
        $BIN_ECHO -e " Package [glibc] not found. Installing.. "
        apt-get install glibc
    elif
        $BIN_ECHO -e " All required packages installed.. "
    fi
fi

第 156 行:意外标记“fi”附近的语法错误

如何将这两个语句放在一起?

4

1 回答 1

4

]在每次测试的决赛之前,您必须有一个空格。

例如:

if [ $DISTRO = "REDHAT"] || [ $DISTRO = "FEDORA"]; then

必须重写为:

 if [ "$DISTRO" = REDHAT ] || [ "$DISTRO" = FEDORA ]; then

或者

if test "$DISTRO" = REDHAT || test "$DISTRO" = FEDORA; then

另请注意,没有理由引用文字字符串,但您应该引用变量。

你也可以这样做:

if test "$DISTRO" = REDHAT -o "$DISTRO" = FEDORA; then

或者

case "$DISTRO" in
REDHAT|FEDORA) ... ;;
DEBIAN) ... ;;
esac
于 2012-10-09T19:15:04.880 回答