14.6.2 Comparing strings with functions

Function: mbfl_string_equal str1 str2

Return successfully if the arguments are equal when lexicographically compared as strings; otherwise return unsuccessfully. Examples:

mbfl_string_equal '' ''                 ⇒ 0
mbfl_string_equal 'a' ''                ⇒ 1
mbfl_string_equal '' 'a'                ⇒ 1
mbfl_string_equal 'ciao' 'ciao'         ⇒ 0
mbfl_string_equal 'ciao' 'hello'        ⇒ 1
Function: mbfl_string_not_equal str1 str2

Return successfully if the arguments are not equal when lexicographically compared as strings; otherwise return unsuccessfully.

Function: mbfl_string_is_yes STR
Function: mbfl_string_is_no STR

Return true if the string STR is equal to, respectively, ‘yes’ or ‘no’; otherwise return false.

Function: mbfl_string_is_true STR
Function: mbfl_string_is_false STR

Return true if the string STR is equal to, respectively, ‘true’ or ‘false’; otherwise return false.

Function: mbfl_string_less str1 str2

Return successfully if str1 is less than str2 when lexicographically compared as strings; otherwise return unsuccessfully. Examples:

mbfl_string_less '' ''                  ⇒ 0
mbfl_string_less 'a' ''                 ⇒ 0
mbfl_string_less '' 'a'                 ⇒ 1
mbfl_string_less 'ciao' 'ciao'          ⇒ 1
mbfl_string_less 'ciao' 'hello'         ⇒ 0
mbfl_string_less 'hello' 'ciao'         ⇒ 1
Function: mbfl_string_greater str1 str2

Return successfully if str1 is greater than str2 when lexicographically compared as strings; otherwise return unsuccessfully. Examples:

mbfl_string_greater '' ''               ⇒ 1
mbfl_string_greater 'a' ''              ⇒ 0
mbfl_string_greater '' 'a'              ⇒ 1
mbfl_string_greater 'ciao' 'ciao'       ⇒ 1
mbfl_string_greater 'ciao' 'hello'      ⇒ 1
mbfl_string_greater 'hello' 'ciao'      ⇒ 0
Function: mbfl_string_less_or_equal str1 str2

Return successfully if str1 is less than, or equal to, str2 when lexicographically compared as strings; otherwise return unsuccessfully. Examples:

mbfl_string_less_or_equal '' ''                 ⇒ 0
mbfl_string_less_or_equal 'a' ''                ⇒ 1
mbfl_string_less_or_equal '' 'a'                ⇒ 0
mbfl_string_less_or_equal 'ciao' 'ciao'         ⇒ 0
mbfl_string_less_or_equal 'ciao' 'hello'        ⇒ 0
mbfl_string_less_or_equal 'hello' 'ciao'        ⇒ 1
Function: mbfl_string_greater_or_equal str1 str2

Return successfully if str1 is greater than, or equal to, str2 when lexicographically compared as strings; otherwise return unsuccessfully. Examples:

mbfl_string_greater_or_equal '' ''              ⇒ 0
mbfl_string_greater_or_equal 'a' ''             ⇒ 0
mbfl_string_greater_or_equal '' 'a'             ⇒ 1
mbfl_string_greater_or_equal 'ciao' 'ciao'      ⇒ 0
mbfl_string_greater_or_equal 'ciao' 'hello'     ⇒ 1
mbfl_string_greater_or_equal 'hello' 'ciao'     ⇒ 0
Function: mbfl_string_compare str1 str2

Compare str1 and str2:

  • if str1 = str2 return 0;
  • if str1 < str2 return 1;
  • if str1 > str2 return 2.
mbfl_string_compare '' ''               ⇒ 0
mbfl_string_compare 'a' ''              ⇒ 2
mbfl_string_compare '' 'a'              ⇒ 1
mbfl_string_compare 'ciao' 'ciao'       ⇒ 0
mbfl_string_compare 'ciao' 'hello'      ⇒ 1
mbfl_string_compare 'hello' 'ciao'      ⇒ 2
Function: mbfl_string_equal_substring STRING POSITION PATTERN

Return true if the substring starting at POSITION in STRING is equal to PATTERN; else return false. If POSITION plus the length of PATTERN is greater than the length of STRING: the return value is false, always.


This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.