gpt4 book ai didi

linux - 语法检查。第二组 if 语句

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:40:31 28 4
gpt4 key购买 nike

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”附近的语法错误

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

最佳答案

在每个测试的最后一个 ] 之前必须有一个空格。

例如:

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

关于linux - 语法检查。第二组 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12806839/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com