linux shell if语句

时间:2021-04-23 11:53:02   收藏:0   阅读:0

 

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

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!