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

 

linux shell if语句

上一篇:linux判断进程是否存在


下一篇:Linux脚本中$#、$0、$1、$@、$*、$$、$?