linux shell if语句

时间:2021-04-22 16:24:15   收藏:0   阅读:31

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!