Shell Script Operators

 

File operators

Operator Returns true if:
-d file file exists and is a directory
-e file file exists
-f file file exists and is a regular file
-r file file exists and you have read permission on it
-s file file exists and is more than 0 bytes in size
-w file You have write permission on file
-x file You have execute permission on file, or search permission if it is a directory
-O file You are the owner of file
-G file You are a member of the group that owns the file
file1 -nt file2 file1 is newer than file2
file1 -ot file2 file1 is older than file2

Integer operators

Operator Returns true if:
var1 -lt var2 var1 is less than var2
var1 -le var2 var1 is less than or equal to var2
var1 -eq var2 var1 is equal to var2
var1 -ne var2 var1 is not equal to var2
var1 -gt var2 var1 is greater than var2
var1 -ge var2 var1 is greater than or equal to var2

String operators

Operator Returns true if:
str1 = str2 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 non-null (i.e. is not an empty string)
-z str1 str1 is null (i.e. has length zero)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s