Comparison Operators
Here are the common comparison operators:
-
>
Used to test whether a given value is greater than the other.
-
>=
Used to test whether a given value is greater than or equal to the other.
-
<
Used to test whether a given value is less than the other.
-
<=
Used to test whether a given value is less than or equal to the other.
-
==
Used to test whether a given value is equal to the other.
-
!=
Used to test whether a given value is not equal to the other.
-
><
Used to test whether a given substring exists within a string. For example, '
123'><'abcd123def
' evaluates toTRUE
.-
>!<
Used to test whether a given substring does not exist within a string. In this case, '
123'>!<'abcd123def
' evaluates toFALSE
.-
=~
Used to match a regular expression. Using this operator is similar to calling the
ereg( )
function call, which performs a similar operation. For example, the statementstr =~ '^[GET / HTTP/1.0\r\n\r\n][.]*')
evaluates toTRUE
only ifstr
begins with the stringGET / HTTP/1.0\r\n\r\n
.-
!~
Used to test whether a regular expression does not match. It is the opposite of the
=~
operator.-
[]
Used to select a character from a string by index. For example, if
mystring
isa1b2c3
,mystring[3]
evaluates to2
.
Get Network Security Tools now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.