shell编程中if判断语句中的判断选项
条件表达式:
文件表达式
–b file 当file存在并且是块文件时返回真
-c file 当file存在并且是字符文件时返回真
-d file 当pathname存在并且是一个目录时返回真
-e pathname 当pathname指定的文件或目录存在时返回真
-f file 当file存在并且是正规文件时返回真
-g pathname 当由pathname指定的文件或目录存在并且设置了SGID位时返回为真
-h file 当file存在并且是符号链接文件时返回真,该选项在一些老系统上无效
-k pathname 当由pathname指定的文件或目录存在并且设置了“粘滞”位时返回真
-p file 当file存在并且是命令管道时返回为真
-r file 当由pathname指定的文件或目录存在并且可读时返回为真
-s file 当file存在文件大小大于0时返回真
-u pathname 当由pathname指定的文件或目录存在并且设置了SUID位时返回真
-w pathname 当由pathname指定的文件或目录存在并且可执行时返回真。一个目录为了它的内容被访问必然是可执行的。
-o pathname 当由pathname指定的文件或目录存在并且被子当前进程的有效用户ID所指定的用户拥有时返回真。
-x file 如果文件file存在且可执行,则返回真
-z STRING 如果字符串长度为0则为真
整数变量表达式
if [ int1 -eq int2 ] 如果int1等于int2if [ int1 -ne int2
] 如果不等于
if [ int1 -ge int2 ] 如果>=
if [ int1 -gt int2 ] 如果>
if [ int1 -le int2 ] 如果<=
if [ int1 -lt int2 ] 如果<
if [ $string1 != $string2 ] 如果string1不等于string2
if [ -n $string ] 如果string 非空(非0),返回0(true)
if [ -z $string ] 如果string 为空
if [ $sting ] 如果string 非空,返回0 (和-n类似)
if [ int1 -ge int2 ] 如果>=
if [ int1 -gt int2 ] 如果>
if [ int1 -le int2 ] 如果<=
if [ int1 -lt int2 ] 如果<
字符串变量表达式
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类似)