Comparing a string of characters
The second keyword for string comparison is equal
.
The syntax for the string
command is as follows:
string equal nocase length int string1 string2
When invoked with the equal
keyword the string
command will perform a character-by-character comparison of the two strings provided.
The equal
keyword accepts two switches, as follows:
-nocase
Strings are compared in a case insensitive manner
-length int
Instructs the interpreter to only perform the comparison on the first length characters
How to do it…
In the following example, we will determine if the values passed as string1
and string2
are equal. Return values from the commands are provided for clarity. Enter the following command:
% string equal Monday monday 0
How it works…
As you can see, the string equal
command has compared the two strings provided and found them to not be a match. When string
is invoked with the equal
keyword it will perform a character-by-character comparison of the two strings provided...