Search This Blog

Bash: check if string contains substring

  • method 1:
    if [[ $str == *"AAA"* ]]; then
        echo "yes"
    else
    	echo "no"
    fi
    	
  • method 2:
    if [[ $str =~ "AAA" ]]; then
        echo "yes"
    else
    	echo "no"
    fi
    	



see also

No comments:

Post a Comment