next up previous contents index
Next: The strcicmp Command Up: String Comparison and Global Previous: String Comparison and Global   Contents   Index


The strcmp Command

The strcmp command is used for string comparison in control structures.

strcmp [varname] string1 string2
This supports the original Spice3 strcmp which returns is value in a given variable, and the WRspice convention where the comparison value is returned in the global return value (accessible with ``$?'').

In either case, the comparison value is a number that is less than, equal to, or greater than zero according to whether string1 is lexically before, equal to, or after string2.

If three arguments are given, the first argument is taken as the name of a variable which is set to the comparison value. This convention is supported for backwards compatibility, of this function only. Otherwise, the global return value will be set to this value. The other arguments are literal strings.

Example

.control
set str1="abcd efgh"
set str2="bbcd efgh"
strcmp "$str1" "$str2"
if ($? < 0)
echo "$str1" ahead of "$str2"
else
if ($? = 0)
echo strings are the same
else
echo "$str1" after "$str2"
end
end
.endc


next up previous contents index
Next: The strcicmp Command Up: String Comparison and Global Previous: String Comparison and Global   Contents   Index
Stephen R. Whiteley 2022-09-18