bash字符串中包含
How to test whether a string $str
contains another string $needle
in Bash?
如何在Bash中测试字符串 $str
是否包含另一个字符串$needle
?
You can use this piece of Bash script:
您可以使用这段Bash 脚本 :
[[ "$str" == *"$needle"* ]]
A usage example:
一个用法示例:
$ str="abcde hello"
$ needle1="deh"
$ needle2="de hello"
$ [[ "$str" == *"$needle1"* ]] && echo "matched"
$ [[ "$str" == *"$needle2"* ]] && echo "matched"
matched
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。
翻译自: https://www.systutorials.com/how-to-do-contains-string-test-in-bash/
bash字符串中包含