码迷,mamicode.com
首页 > 系统相关 > 详细

linux shell if语句

时间:2021-04-23 11:53:02      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:root   rgba   shell   color   int   div   bnu   inux   nbsp   

 

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语句

标签:root   rgba   shell   color   int   div   bnu   inux   nbsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!