比较运算符

来自于这个课本:

Advanced Bash-Scripting Guide:

详细参考链接:

Other Comparison Operatorshttps://tldp.org/LDP/abs/html/comparison-ops.html

if Else if and elif

还有test测试命令

详细参考链接:

Test Constructshttps://tldp.org/LDP/abs/html/testconstructs.html#TTESTREF

hl@ubuntu:~$ man test( EXPRESSION )EXPRESSION is true! EXPRESSIONEXPRESSION is falseEXPRESSION1 -a EXPRESSION2both EXPRESSION1 and EXPRESSION2 are trueEXPRESSION1 -o EXPRESSION2either EXPRESSION1 or EXPRESSION2 is true-n STRINGthe length of STRING is nonzeroSTRING equivalent to -n STRING-z STRINGthe length of STRING is zeroSTRING1 = STRING2the strings are equalSTRING1 != STRING2the strings are not equalINTEGER1 -le INTEGER2INTEGER1 is less than or equal to INTEGER2INTEGER1 -lt INTEGER2INTEGER1 is less than INTEGER2INTEGER1 -ne INTEGER2INTEGER1 is not equal to INTEGER2FILE1 -ef FILE2FILE1 and FILE2 have the same device and inode numbersFILE1 -nt FILE2FILE1 is newer (modification date) than FILE2FILE1 -ot FILE2FILE1 is older than FILE2-b FILEFILE exists and is block special-c FILEFILE exists and is character special-d FILEFILE exists and is a directory-e FILEFILE exists-f FILEFILE exists and is a regular file-g FILEFILE exists and is set-group-ID-G FILEFILE exists and is owned by the effective group ID-h FILEFILE exists and is a symbolic link (same as -L)-k FILEFILE exists and has its sticky bit set-L FILEFILE exists and is a symbolic link (same as -h)-O FILEFILE exists and is owned by the effective user ID-p FILEFILE exists and is a named pipe-r FILEFILE exists and read permission is granted-s FILEFILE exists and has a size greater than zero-S FILEFILE exists and is a socket-t FD  file descriptor FD is opened on a terminal-u FILEFILE exists and its set-user-ID bit is set-w FILEFILE exists and write permission is granted-x FILEFILE exists and execute (or search) permission is granted

NOTE: Binary -a and -o are inherently ambiguous.  Use 'test EXPR1 && test EXPR2' or 'test EXPR1 || test EXPR2' instead.

bash脚本比较运算符和if else和test命令相关推荐

  1. Bash 脚本如何创建临时文件:mktemp 命令和 trap 命令教程

    有时,Bash 脚本需要创建临时文件或临时目录. 常见的做法是,自己在/tmp目录里面生成一个文件,这样做有很多弊端.本文介绍如何安全地处理临时文件. 一.临时文件的安全问题 直接创建临时文件,尤其在 ...

  2. 如何在bash脚本中提示用户进行确认? [重复]

    本文翻译自:How do I prompt a user for confirmation in bash script? [duplicate] This question already has ...

  3. 检查传递给Bash脚本的参数数量

    本文翻译自:Check number of arguments passed to a Bash script I would like my Bash script to print an erro ...

  4. Bash脚本获取自身完整路径的可靠方法

    本文翻译自:Reliable way for a Bash script to get the full path to itself [duplicate] This question alread ...

  5. 从脚本本身获取Bash脚本的源目录

    如何获取其中的目录路径的Bash脚本所在,该脚本里面 ? 例如,假设我要使用Bash脚本作为另一个应用程序的启动器. 我想将工作目录更改为Bash脚本所在的目录,以便可以对该目录中的文件进行操作,如下 ...

  6. Bash 脚本 set 命令教程

    http://www.ruanyifeng.com/blog/2017/11/bash-set.html set命令是 Bash 脚本的重要环节,却常常被忽视,导致脚本的安全性和可维护性出问题.本文介 ...

  7. 如何在Bash脚本中将Heredoc写入文件?

    如何在Bash脚本中将Here文档写入文件? #1楼 代替使用cat和I / O重定向,可以使用tee代替: tee newfile <<EOF line 1 line 2 line 3 ...

  8. 初学者编写bash脚本教程

    初学者编写bash脚本教程 bash shell script 定义 bash bash是命令语言解释器.广泛用于各种gun/unix系统上的默认命令解释器.全程叫做"Bourne-Agai ...

  9. sh脚本和bash脚本_使用此简单的Bash脚本在家打印双面文档

    sh脚本和bash脚本 我们家里有一台激光打印机. 惠普(Hewlett Packard)LaserJet Pro CP1525nw彩色打印机是一种较旧的型号,但它是一台出色的打印机,可以可靠地进行彩 ...

  10. Bash脚本编程之算术运算

    简介 Bash所支持的算术运算和C语言是一样的,这里指的是操作符(operator)以及它们的优先级(precedence).结合性(associativity)和值,详见Shell Arithmet ...

最新文章

  1. 时间计时android程序,Android 时间计时器控件 Chronometer
  2. 使用消息来处理多线程程序中的一些问题
  3. 字符设备驱动笔记——中断方式按键驱动之linux异常处理结构(四)
  4. 初探swift语言的学习笔记十一(performSelector)
  5. 基于Exchange 2003的搭建高可用的邮件平台 之一:群集的配置
  6. 21天学通c语言第四版pdf,21天学通Visual C++ PDF扫描版[116MB]
  7. java 可以重载等于号码_Java面试之Java基础4——重载与重写的区别
  8. Pandas 求余运算
  9. Java 数据库编程 ResultSet 的 使用方法
  10. linux脚本编写乘法口诀,shell脚本编写乘法口诀
  11. itest听力答案2020_itest答案
  12. JQuery插件之图片轮播插件–slideBox
  13. asp.net中gridview的绑定数据源实现增删改查
  14. 洛谷P1941 飞扬的小鸟
  15. 一文带你复习计网中的重点知识(一万五千字长文)
  16. 【GIS小白学习笔记】Excel加至Arcgis坐标分带选择
  17. 让你的努力配得上你的梦想书摘
  18. Danar程序员之家
  19. 国标28181:什么是RTP协议与RTCP协议
  20. Widget原理分析

热门文章

  1. twisted系列教程二–缓慢的诗
  2. 吴彦祖计算机系统班 百度网盘,哪位吴彦祖(来自伸手党的夸赞) 有老詹的那场g6的百度云盘录像啊?我很需要...
  3. php网站代码报告,使用Checkstyle报告(来自CodeSniffer)可视化PHP代码
  4. Autocompletetextview width fill parent问题
  5. Android开发之Activity(实现Activity跳转)
  6. 使用git来管理微信小程序
  7. 整数规划_教学 | 线性(整数)规划的若干建模技巧
  8. java 处理时间的类_详解JAVA 时间处理相关类
  9. mac 环境 Android Studio升级后Gradle project Sync Failed解决方法
  10. python语言编写一个生成九宫格图片的代码_python生成九宫格图片