当前位置:首页 > 操作系统 > Linux

linux shell if语句

 

1、测试1

            
                [root@centos7 test2]# ls
a.txt
[root@centos7 test2]# 
                if [ -e a.txt ]; then echo "exist";else echo "no nxist"; fi
exist
[root@centos7 test2]# if [ -e b.txt ]; then echo "exist";else echo "no nxist"; fi
no nxist
        

 

2、测试2

            [root@centos7 test2]# seq 3 > a.txt
[root@centos7 test2]# seq 5 > b.txt
[root@centos7 test2]# anum=$(wc -l a.txt|awk {print $1})
[root@centos7 test2]# bnum=$(wc -l b.txt|awk {print $1})
[root@centos7 test2]# if [ $anum -gt $bnum ]; then echo "a > b"; else echo "b > a"; fi
b > a
        

 

原文:https://www.cnblogs.com/liujiaxin2018/p/14689068.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐