首页 > 其他 > 详细

条件判断语法

时间:2017-01-10 00:06:44      阅读:339      评论:0      收藏:0      [点我收藏+]
  1. [root@old_boy scripts]# cat judgehost.sh   

  2. #!/bin/bash  

  3. echo "please input ip address:" 

  4. read ip  

  5. [ -n "`grep "$ip " /etc/hosts`" ] && \  #注意前面的过滤条件结尾带有空格。  

  6. echo "The hostname is: `grep "$ip " /etc/hosts |awk ‘{print $2}‘`" || \  

  7. echo "The ip is invalid" 

[ -n "ddd" ] && echo 1 || echo 0


三元运算符


awk ‘BEGIN{a="b";print a=="b"?"ok":"err";}‘ 



条件判断语法

原文:http://benchmarking.blog.51cto.com/12343634/1890450

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!