首页 > 系统服务 > 详细

shell的if嵌套

时间:2018-02-09 21:18:02      阅读:254      评论:0      收藏:0      [点我收藏+]

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

  

shell的if嵌套

原文:https://www.cnblogs.com/weifeng1463/p/8436526.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!