如何修复Bash脚本中的[[:missing`]''错误?

时间:2019-09-27 18:53:33

标签: bash

我正在尝试编写脚本。

这是我的代码的一部分

if [ #? -ne 0 ]
then
    echo "Args:"

    if [ -r $word.args ]
    then
        cat $word.args
    fi

    echo "Expected:"
    cat $word.out
    echo "Actual:"
    cat $tempfile
fi

当我进行一些测试时,它总是显示“ [:missing`]'” 在此行

if [ #? -ne 0 ]

为什么?

1 个答案:

答案 0 :(得分:1)

这是因为行中有语法错误:

if [ #? -ne 0 ]

要更正它,请将其更改为:

# If you are interested in getting number of arguments
if [ $# -ne 0 ]

OR

# If you are interested in getting exit status code of last command i.e.
# whether or not the last command executed successfully
if [ $? -ne 0 ]

注意#用于行注释。因此,它将忽略#之后到该行末尾的所有文本。

您可以找到this link useful

相关问题