解决方法
您可以使用案例陈述:
case "$myvar" in *string*) echo yes ;; * ) echo no ;; esac
您所要做的就是用字符串代替您需要的任何东西.
例如:
case "HELLOHELLOHELLO" in *HELLO* ) echo "Greetings!" ;; esac
或者,换句话说:
string="HELLOHELLOHELLO" word="HELLO" case "$string" in *$word*) echo "Match!" ;; * ) echo "No match" ;; esac
当然,你必须意识到$word不应包含魔术全局字符,除非你打算进行全局匹配.