# strstr() -- locate a substring # Usage: strstsr string match # # Example 1: # # string="saya suka makan"; # if strstr "${string}" "suk"; then # echo "OK"; # fi # # Example 2: # # buff="$(ps ax)"; # if ! strstr "${buff}" "httpd"; then # echo "service httpd down"; # fi strstr() { [ $# -eq 2 ] || return 1; [ "$1" = "$2" ] || [[ "$1" = *$2* ]] && return 0; return 1; }