[bash] Condition Tests





Table 5-3. Arithmetic test operators

Test

Comparison

-lt

Less than

-le

Less than or equal

-eq

Equal

-ge

Greater than or equal

-gt

Greater than

-ne

Not equal


Table 5-2. File attribute operators

Operator

True if...

-a file

file exists

-d file

file exists and is a directory

-e file

file exists; same as -a

-f file

file exists and is a regular file (i.e., not a directory or other special type of file)

-r file

You have read permission on file

-s file

file exists and is not empty

-w file

You have write permission on file

-x file

You have execute permission on file, or directory search permission if it is a directory

-N file

file was modified since it was last read

-O file

You own file

-G file

file's group ID matches yours (or one of yours, if you are in multiple groups)

file1 -nt file2

file1 is newer than file2 [6]

file1 -ot file2

file1 is older than file2


[6] Specifically, the -nt and -ot operators compare modification times of two files.


Table 5-1. String comparison operators

Operator

True if...

str1 = str2[4]

str1 matches str2

str1 != str2

str1 does not match str2

str1 < str2

str1 is less than str2

str1 > str2

str1 is greater than str2

-n str1

str1 is not null (has length greater than 0)

-z str1

str1 is null (has length 0)


posted @ 2011-08-10 15:17  油炸西瓜  阅读(240)  评论(0编辑  收藏  举报