Spice3f5

strcmp

Set $varname to strcmp(s1, s2)

General form

strcmp variable string1 string2

Compare two strings and set the variable named to the result: negative if string1 sorts before string2, 0 if they are the same, and positive if it sorts after. Quotes around the strings are removed first. This is useful in command scripts, with if.

Example

strcmp res "abc" "abd"
echo $res
set mode = fast
strcmp same $mode fast
if $same = 0
  echo fast mode
end

The first echo prints -1.

All commands