由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - bash programming problem on string
相关主题
shell script for "for" loophow to extract data every 20 lines.
which shell is the best among csh, ksh, bsh?shell script question
为什么我就是不会写Shell script?请问在unix命令窗口中英文乱码是怎么回事啊?
[转载] 简单问题 -- about shell script求助一个shell script
[转载] a question about shell scriptbourne shell program Question
hwo to solve ita puzzle
AWK problem, SOS!read file help!
求平均值--unix commandRe: small but nice thing to know
相关话题的讨论汇总
话题: string话题: bash话题: echo话题: expr
进入Unix版参与讨论
1 (共1页)
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.

1 (共1页)
进入Unix版参与讨论
相关主题
Re: small but nice thing to know[转载] a question about shell script
Re: 怎么在bash script里面改变xterm窗口的标题?hwo to solve it
Re: Bash一问:怎么includeAWK problem, SOS!
[转载] About the history求平均值--unix command
shell script for "for" loophow to extract data every 20 lines.
which shell is the best among csh, ksh, bsh?shell script question
为什么我就是不会写Shell script?请问在unix命令窗口中英文乱码是怎么回事啊?
[转载] 简单问题 -- about shell script求助一个shell script
相关话题的讨论汇总
话题: string话题: bash话题: echo话题: expr