If statement 引用单词的if语句错误,应使用-[:!=:一元运算符

If statement 引用单词的if语句错误,应使用-[:!=:一元运算符,if-statement,If Statement,当运行我的bash脚本时,它会在运行时抛出此错误 在该功能中: function undeploy { echo Removing ${SITE} from ${i} .... rm -rf /net/${i}/${JBPATH}/${FILEOLD} if [ $? -ne 0 ] ; then echo "Nothing to remove, proceeding to copy new WAR"

当运行我的bash脚本时,它会在运行时抛出此错误

在该功能中:

function undeploy {
        echo Removing ${SITE} from ${i} ....
        rm -rf /net/${i}/${JBPATH}/${FILEOLD}
        if [ $? -ne 0 ] ; then
                echo "Nothing to remove, proceeding to copy new WAR"
        else
        echo "WAR removed, waiting for Undeploy...."
        tail -1f /net/${i}/var/log/jboss/server.log | while read LINE ; do if [[ "${LINE}" =~ "Undeployed" ]] ; then if [[ ${LINE} =~ "${SITE}" ]] ; then break ; fi ; fi ; done
        check
        fi
        if [ $4 != force ]; then
        echo "Un-deployment completed ${i}. Continue?"
        read Continue
        case "${Continue}" in
        Y|y|yes|YES|Yes) echo "Continuing"
        ;;
        *) echo "Exiting"
        exit 1
        ;;
        esac
        fi
        }
如果[$4!=force];行导致错误

有人知道为什么吗?我试过用单引号和双引号写force和$4。还是没有运气

你知道这里的语法出了什么问题吗


如果您需要更多信息,请询问。

如果没有定义${4}变量(如果传递给脚本的变量少于4个),则可能会失败。请尝试使用case,或执行另一个测试以查看是否存在$4

exmaple:if[$#-ge 4];那么(您的函数)


如果[-n$4];那么(你的函数)

如果[“$4”!=force]
你是对的。添加双“[[”“]”对我来说很有效。