尝试if else条件时意外结束文件

时间:2017-07-31 13:24:33

标签: shell

我刚刚开始学习shell并且在尝试使用条件时遇到此错误team.sh: line 9: syntax error: unexpected end of file: -

    #!/bin/sh
    result=2
    tmp=2
    if [ $result == $tmp ]
            echo "App is running"
    else
            echo "App is down"
    fi

1 个答案:

答案 0 :(得分:1)

在shell中使用条件语句有多种方法。其中很少是: -

方法1: -

#!/bin/sh
result=2
tmp=2
if [ $result == $tmp ]
then 
        echo "App is running"
else
        echo "App is down"
fi

方法2: -

#!/bin/sh
result=2
tmp=2
if [ $result == $tmp ] ; then
                echo "App is running"
else
                echo "App is down"
fi

this链接非常有用