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
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
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 in a similar manner as the compare
keyword. The difference is in the return values; equal
returns a 1
if the strings are identical or a 0
if the strings do not match.
3.148.103.210