传统if 从句子——以条件表达式作为 if条件
if [ 条件表达式 ]
then
 command
 command
 command
else
 command
 command
fi
   
条件表达式

  • 文件表达式

if [ -f  file ]    如果文件存在
if [ -d ...   ]    如果目录存在
if [ -s file  ]    如果文件存在且非空 
if [ -r file  ]    如果文件存在且可读
if [ -w file  ]    如果文件存在且可写
if [ -x file  ]    如果文件存在且可执行

  • 整数变量表达式

if [ int1 -eq int2 ]  如果int1等于int2      equal
if [ int1 -ne int2 ]  如果不等于       not equal
if [ int1 -ge int2 ]  如果>=        greater equal
if [ int1 -gt int2 ]   如果>       greater than
if [ int1 -le int2 ]   如果<=        less equal
if [ int1 -lt int2 ]    如果<       less than

  • 字符串变量表达式

If  [ $a = $b ]                 如果string1等于string2   字符串允许使用赋值号做等号
if  [ $string1 !=  $string2 ]   如果string1不等于string2       
if  [ -n $string  ]             如果string 非空(非0),返回0(true)  
if  [ -z $string  ]             如果string 为空
if  [ $sting ]                  如果string 非空,返回0 (和-n类似)

最新文章

  1. 【processing】小代码
  2. java web开发必备知识
  3. 如何在VS C++中高亮用户自定义关键字
  4. Ubuntu虚拟机与Window、Arm的通信
  5. SpringMVC Maven创建项目
  6. poj Pie
  7. Intel 编译Boost库
  8. DevExtreme 学习应用[3]
  9. jsp页面的地址
  10. 微信小程序域名配置问题
  11. IntelliJ IDEA编辑器光标定位错误的问题!
  12. markdown 相关零碎知识
  13. Linux 定时任务 crontab 和 Systemd Timer
  14. Python3学习之路~0 目录
  15. JavaScript对象继续总结
  16. 用C#自定义一个简单的集合
  17. Java应用中使用ShutdownHook友好地清理现场
  18. 论 BUG调试与(程序猿)初学者
  19. 【LeetCode】Permutations II 解题报告
  20. mysql select *... where id in (select 字符串 from ... )查询结果问题?

热门文章

  1. 扯下Python的super()
  2. 9)用request方式
  3. 吴裕雄--天生自然 pythonTensorFlow自然语言处理:交叉熵损失函数
  4. SQL服务器攻击总结-注入
  5. elasticsearch minhash 测试应用
  6. [学习笔记]连通分量与Tarjan算法
  7. 求Fibonacii数列的第40个数
  8. WxProperties WxConfig
  9. VMware 三种网络配置解释
  10. 传输层TCP和UDP