怎么在SHELL里查看一个变量是否包含某个字符串

如题所述

比如变量是str str="this is a string" 要想在判断str中是否含有"this"这个字符串,下面的语句是可行的 [[ $str =~ "this" ]] && echo "\$str contains this" [[ $str =~ "that" ]] || echo "\$str does NOT contain this"
温馨提示:答案为网友推荐,仅供参考
相似回答