bash字符串中包含_如何在Bash中进行“包含字符串”测试?

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字符串中包含

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值