string1 = string2 True if the strings are equal
(字符串相等则为真)
string1 != string2 True if the strings are not equal
(字符串不等则为真)
-n string True if the string is not null
(如果字符串不为空则为真)
-z string True if the string is null (an empty string)
(字符串为空则为真) Arithmetic ComparisonResult
expression1 -eq expression2 True if the expressions are equal
(两表达式相等则为真)
expression1 -ne expression2 True if the expressions are not equal
(两表达式不等则为真)
expression1 -gt expression2 True if expression1 is greater than expression2
(表达式1 > 表达式2 则为真)
expression1 -ge expression2 True if expression1 is greater than or equal to expression2
(表达式1 >= 表达式2 则为真)
expression1 -lt expression2 True if expression1 is less than expression2
(表达式1 < 表达式2 则为真)
expression1 -le expression2 True if expression1 is less than or equal to expression2
(表达式1 <= 表达式2 则为真)
! expression True if the expression is false, and vice versa
File ConditionalResult
-d file True if the file is a directory
(若文件为一目录则为真)
-e file True if the file exists. Note that historically the -e option has not been portable, so -f is usually used.
(文件存在则为真.注意,-e 选项显得不太轻便,故 -f 则比较常用)
-f file True if the file is a regular file
(文件是个普通文件则为真)
-g file True if set-group-id is set on file
(如果文件的 sgid 设置了就为真)
-r file True if the file is readable
(如果文件可读则为真)
-s file True if the file has nonzero size
(文件非 0 字节时为真)
-u file True if set-user-id is set on file
(如果文件设置了 suid 则为真)
-w file True if the file is writable
(如果文件可写则为真)
-x file True if the file is executable
(如果文件可执行则为真)
作者: beyes 时间: 2009-1-16 20:03 标题: 示例代码一 #!/bin/sh
if [ -f /bin/bash ] then echo "file /bin/bash exists" fi
if [ -d /bin/bash ] then echo "/bin/bash is a directory" else echo "/bin/bash is NOT a directory" fi