最常用的简化if语句:

&& 如果是“前面”,则“后面”

[ -f /var/run/dhcpd.pid ] && rm /var/run/dhcpd.pid 检查 文件是否存在,如果存在就删掉

|| 如果不是“前面”,则后面

[ -f /usr/sbin/dhcpd ] || exit 0 检验文件是否存在,如果存在就退出

示例:用简化 if 和$1,$2,$3来检测参数,不合理就调用help

[ -z "$1" ] && help 如果第一个参数不存在(-z 字符串长度为0 )

[ "$1" = "-h" ] && help 如果第一个参数是-h,就显示help

[macg@machome ~]$ man test
[(1) User Commands [(1) SYNOPSIS
test EXPRESSION
[ EXPRESSION ] [-n] STRING
the length of STRING is nonzero -n和直接$str都是非0条件 -z STRING
the length of STRING is zero STRING1 = STRING2
the strings are equal STRING1 != STRING2
the strings are not equal INTEGER1 -eq INTEGER2
INTEGER1 is equal to INTEGER2 INTEGER1 -ge INTEGER2
INTEGER1 is greater than or equal to INTEGER2 INTEGER1 -gt INTEGER2
INTEGER1 is greater than INTEGER2 INTEGER1 -le INTEGER2
INTEGER1 is less than or equal to INTEGER2 INTEGER1 -lt INTEGER2
INTEGER1 is less than INTEGER2 INTEGER1 -ne INTEGER2
INTEGER1 is not equal to INTEGER2 FILE1 -nt FILE2
FILE1 is newer (modification date) than FILE2 FILE1 -ot FILE2
FILE1 is older than FILE2 -b FILE
FILE exists and is block special -c FILE
FILE exists and is character special -d FILE
FILE exists and is a directory -e FILE
FILE exists 文件存在 -f FILE
FILE exists and is a regular file 文件存在且是普通文件 -h FILE
FILE exists and is a symbolic link (same as -L) -L FILE
FILE exists and is a symbolic link (same as -h) -G FILE
FILE exists and is owned by the effective group ID -O FILE
FILE exists and is owned by the effective user ID -p FILE
FILE exists and is a named pipe -s FILE
FILE exists and has a size greater than zero -S FILE
FILE exists and is a socket -w FILE
FILE exists and is writable -x FILE
FILE exists and is executable

最新文章

  1. C# ~ 从 委托事件 到 观察者模式 - Observer
  2. UWP webview 键盘bug,回退页面,键盘会弹一下。
  3. 单色半透明-兼容IE7
  4. C#序列化与反序列化方式简单总结
  5. 从浏览器输入url到页面加载完成都发生了什么
  6. 正在使用广告标识符 (IDFA)
  7. 使用批处理文件,自动设置计算机IP地址
  8. android 开发 对图片编码,并生成gif图片
  9. SFTPTool 和 FTPTooL.java
  10. Redhat 官方Performance_Tuning_Guide
  11. JS封深入了解
  12. 第45篇 js操作打开本地程序
  13. integer与int区别以及integer.values()方法详解
  14. deb包转化为rpm包
  15. JAVA核心技术I---JAVA基础知识
  16. tensorflow中文教程
  17. 详解如何在 Linux 中安装最新的 Python 3.6 版本
  18. IE8下面parseInt('08')、parseInt('09')会转成0
  19. 面试:vector类的简单实现
  20. C. NN and the Optical Illusion(几何)

热门文章

  1. xcode7 安装 KSImageNamed
  2. Vue进阶篇
  3. python中__dict__与dir()的区别
  4. Spring Boot 整合MyBatis(1)
  5. Python的环境搭建——万丈高楼平地起
  6. 导航控制器(UINavigationController)
  7. nyoj 737 石子合并 http://blog.csdn.net/wangdan11111/article/details/45032519
  8. hiho1393二分图多重匹配
  9. jni java C/C++ 相互调用
  10. 三周学会小程序第四讲:Heroku 绑定 Github 自动部署