Official document: Help test
File operators:-A FILE Trueif fileexists. -B FILE Trueif fileis block special. -C FILE Trueif fileis character Special. -D FILE Trueif fileis a directory. -E FILE Trueif fileexists. -F FILE Trueif fileexists and is a regularfile. -G FILE Trueif fileIs set-group-ID. -H FILE Trueif fileis a symbolic link. -L FILE Trueif fileis a symbolic link. -K FILE Trueif filehave its ' sticky'bit set.-P FILE Trueif fileis a named pipe. -R FILE Trueif fileis readable by you . -S FILE Trueif fileexists and is not empty. -S FILE Trueif fileis a socket. -T FD TrueifFD is opened on a terminal. -U FILE TrueifThefileIs set-user-ID. -WFILE TrueifThefileis writable by you . -X FILE TrueifThefileis executable by you . -O FILE TrueifThefileis effectively owned. -G FILE TrueifThefileis effectively owned by your group. -N FILE TrueifThefilehad been modified since it was Lastread. FILE1-nt FILE2 TrueifFile1 is newer than file2 (according to modificationDate). FILE1-ot FILE2 TrueifFile1 is older than file2. FILE1-ef FILE2 Trueiffile1 is a hard link to file2. String operators:-Z STRING Trueif stringIs empty. -n String String Trueif stringis not empty. STRING1=STRING2 TrueifThe strings is equal. STRING1!=STRING2 TrueifThe strings is not equal. STRING1<STRING2 TrueifSTRING1 sorts before STRING2 lexicographically. STRING1>STRING2 TrueifSTRING1 sorts after STRING2 lexicographically. Other operators:-O OPTION TrueifThe Shell option option is enabled. ! EXPR Trueif ExprIsfalse. EXPR1-A EXPR2 TrueifBoth Expr1 and EXPR2 aretrue. EXPR1-O EXPR2 TrueifEither Expr1 OR EXPR2 istrue. Arg1 OP arg2 arithmetic tests. OP is one of-eq,-NE,-lt,-le,-GT, or-GE. Arithmetic binary operators returntrue ifARG1 is equal, not-Equal, Less-than, Less-than-or-equal, Greater-than, or greater-than-or-equal than ARG2.
Example:
1. Determine if the file exists
[Email protected] test]# test-f demo. SH -F Demo. SH Echo truetrue! -F Demo. SH Echo true
2. Determine if the string is empty
[[email protected] test]# var=echotruetrueecho True
3. Compare
[[email protected] test]# var=echotruetrue
The Joy of Linux commands--test