s**n 发帖数: 33 | 1 Hi, I want to find out where a string contains another string, for example,
whether "asdfsdxyx1234" contains "xyx1". How can I do that by bash shell
script? I tried expr match and expr index but could not figure it out.
Thanks. | m**h 发帖数: 207 | 2 i use a dumb method:
if echo "asdfsdxyx1234" | grep "xyx1" 1>/dev/null 2>&1; then
blah
blah
fi
【在 s**n 的大作中提到】 : Hi, I want to find out where a string contains another string, for example, : whether "asdfsdxyx1234" contains "xyx1". How can I do that by bash shell : script? I tried expr match and expr index but could not figure it out. : Thanks.
| m***s 发帖数: 13 | 3 a=abcdefg; b=bcd; if ( [[ $a == *$b* ]] ); then echo contain; fi
【在 s**n 的大作中提到】 : Hi, I want to find out where a string contains another string, for example, : whether "asdfsdxyx1234" contains "xyx1". How can I do that by bash shell : script? I tried expr match and expr index but could not figure it out. : Thanks.
| c*****t 发帖数: 1879 | 4 hoho, I was going to use case, but yours is simpler I guess.
【在 m***s 的大作中提到】 : a=abcdefg; b=bcd; if ( [[ $a == *$b* ]] ); then echo contain; fi
| c******y 发帖数: 37 | 5 # Bourne shell
if [ "${str/$substr/}" != "$str" ]; then
echo "is a substing"
else
echo "not a substring"
fi
【在 s**n 的大作中提到】 : Hi, I want to find out where a string contains another string, for example, : whether "asdfsdxyx1234" contains "xyx1". How can I do that by bash shell : script? I tried expr match and expr index but could not figure it out. : Thanks.
|
|