2017-07-31 76 views
0

我剛開始學習外殼,並試圖有條件的,如果別人當我得到這個錯誤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 
+0

你需要寫'如果[$結果= = $ tmp]; then'。請參閱:http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html –

回答

1

有兩種使用殼條件語句多種方式。他們幾個是: -

方法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鏈接可能是有用的