shell脚本编写中,if是可以嵌套的, 
注意,if条件表达式[]中的空格,以及后面的then就行了 
if条件表达式后面的分号“;”可有可无,不影响。

代码如下

myFile='ctr_result.txt'
if [ -e "$myFile" ]; then
        rm $myFile
        result_code=$?
        if [ "$result_code" -ne 0 ]; then
                echo "[ERROR] when delete $myFile"
                exit $result_code
        fi
        echo "$myFile exists, we delete it"
fi


  
 

  

 

实际shell 脚本


if [ $packetanal_ver != 'yechang' ];then
     packetpid=`ps aux|grep  packetAnal|grep -v "grep"|awk '{print $2}'`

     if [ "$packetpid" ];then
          kill -9 $packetpid
          echo "old packetAnal is killed"
     fi
fi

  

相关文章:

  • 2021-06-07
  • 2021-06-08
  • 2021-06-09
  • 2022-02-03
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案