shell命令——if

if中[ ]实际上调用的是test的一种快捷方法。bash的数值和字符串比较运算符:

注意=两边的空格
字符串 数值 为真,如果
x = y x -eq y  
x != y x -ne y  
x < y x -lt y  
x <= y x -le y  
x > y x -gt y  
x >= y  x -ge y  
-n x   x不为空
-z x   x为空

文件属性判断

-d file: file存在且为目录(dict)

-e file:file存在(exist)

-f file:file存在且为普通文件(file)

-r file:用户有file的读权限(read)

-s file:file存在且不为空(?)

-w file:用户有file的写权限(write)

file1 -nt file2:file1比file2新(new than)

file1 -ot file2:file1比file2旧(old than)

原文地址:https://www.cnblogs.com/hbgzy/p/5226976.html