# stristr() -- Case-insensitive strstr() # Usage: stristsr string match # depend: strtolower(): http://www.ronggeng.net/index.php/2009/04/24/strtolower/ # # Example 1: # # string="saya SUKA Makan"; # if stristr "${string}" "suk"; then # echo "OK"; # fi # # Example 2: # # buff="$(ps ax)"; # if ! stirstr "${buff}" "httpd"; then # echo "service httpd down"; # fi stristr() { [ $# -eq 2 ] || return 1; ! type -t strtolower &>/dev/null && return 1; local _str1=$(strtolower "$1"); local _str2=$(strtolower "$2"); [ "$_str1" = "$_str2" ] || [[ "$_str1" = *$_str2* ]] && return 0; return 1; }