Vous êtes sur la page 1sur 2

A brief summary of test operators

Here's a quick list of test operators. It's by no means comprehensive, but its likely to be all you'll need
to remember (if you need anything else, you can always check the bash manpage ... )

number of
operator produces true if...
operands

-n operand non zero length 1

-z operand has zero length 1

-d there exists a directory whose name is operand 1

-f there exists a file whose name is operand 1

-eq the operands are integers and they are equal 2

-neq the opposite of -eq 2

= the operands are equal (as strings) 2

!= opposite of = 2

operand1 is strictly less than operand2 (both operands should be


-lt 2
integers)

operand1 is strictly greater than operand2 (both operands should be


-gt 2
integers)

operand1 is greater than or equal to operand2 (both operands should


-ge 2
be integers)

operand1 is less than or equal to operand2 (both operands should be


-le 2
integers)

The tests below are test conditions provided by the shell:

-b file = True if the file exists and is block special file.


-c file = True if the file exists and is character special file.
-d file = True if the file exists and is a directory.
-e file = True if the file exists.
-f file = True if the file exists and is a regular file
-g file = True if the file exists and the set-group-id bit is set.
-k file = True if the files' "sticky" bit is set.
-L file = True if the file exists and is a symbolic link.
-p file = True if the file exists and is a named pipe.
-r file = True if the file exists and is readable.
-s file = True if the file exists and its size is greater than zero.
-s file = True if the file exists and is a socket.
-t fd = True if the file descriptor is opened on a terminal.
-u file = True if the file exists and its set-user-id bit is set.
-w file = True if the file exists and is writable.
-x file = True if the file exists and is executable.
-O file = True if the file exists and is owned by the effective user id.
-G file = True if the file exists and is owned by the effective group id.
file1 nt file2 = True if file1 is newer, by modification date, than file2.
file1 ot file2 = True if file1 is older than file2.
file1 ef file2 = True if file1 and file2 have the same device and inode numbers.
-z string = True if the length of the string is 0.
-n string = True if the length of the string is non-zero.
string1 = string2 = True if the strings are equal.
string1 != string2 = True if the strings are not equal.
!expr = True if the expr evaluates to false.
expr1 a expr2 = True if both expr1 and expr2 are true.
expr1 o expr2 = True is either expr1 or expr2 is tr

Vous aimerez peut-être aussi