Hi:
I need help.
How to know a string inside another string
for example.
"home" is in "home is mine"
Best Regards
zhengyi
I need help.
How to know a string inside another string
for example.
"home" is in "home is mine"
Best Regards
zhengyi
Ksh:Quote:> Hi:
> I need help.
> How to know a string inside another string
> for example.
> "home" is in "home is mine"
regards,
Ben
> > I need help.
> > How to know a string inside another string
> > for example.
> > "home" is in "home is mine"
> Ksh:
ALL Bourne-type shells (including ksh and bash):Quote:> if [[ $str = *home* ]]; then
> :
> fi
## to generalize, replace '"home is mine"' with a variable
case "home is mine" in
*$str*) echo YES ;;
*) echo NO ;;
esac
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2002, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
> > I need help.
> > How to know a string inside another string
> > for example.
> > "home" is in "home is mine"
> Ksh:
> if [[ $str = *home* ]]; then
> :
> fi
> regards,
> Ben
> > > Hi:
> > > I need help.
> > > How to know a string inside another string
> > > for example.
> > > "home" is in "home is mine"
> > Ksh:
> And bash:
> > if [[ $str = *home* ]]; then
> > :
> > fi
> ALL Bourne-type shells (including ksh and bash):
> ## to generalize, replace '"home is mine"' with a variable
> case "home is mine" in
> *$str*) echo YES ;;
> *) echo NO ;;
> esac
> > > > Hi:
> > > > I need help.
> > > > How to know a string inside another string
> > > > for example.
> > > > "home" is in "home is mine"
> > > Ksh:
> > And bash:
> > > if [[ $str = *home* ]]; then
> > > :
> > > fi
> > ALL Bourne-type shells (including ksh and bash):
> > ## to generalize, replace '"home is mine"' with a variable
> > case "home is mine" in
> > *$str*) echo YES ;;
> > *) echo NO ;;
> > esac
> why the double square brackets in "if [[ $str = *home* ]]; then"?
You cannot use regexp inside single brackets.
Hope it helps
Cyrille
I tend to use expr alot ...Quote:> I need help.
> How to know a string inside another string
> for example.
> "home" is in "home is mine"
if expr "home is mine" : ".*home.*" > /dev/null ; then
echo found
else
echo not found
fi
expr also allows you to use regular expresions.
--
David Thompson
Foster City, CA, USA
1. Find a string in a text file and replace with another string to eof
Hi,
I am trying to write a very simple shell script that will help me find a
string in a text file and replace that same string with another string
from command line.
Something like:
./myscript "foo" "bar"
"foo" is the string to find
"bar" is the string replacement
Multiple replacements in the file, of course.
Thanks.
2. ATI Mach64 Server => Blank Screen
3. -m --string with 3 different strings
4. TuxPaint - new version available
5. how to find a unknown string and then the next line with the string
6. troubles with Linksys EC2T PCMCIA ethernet card
7. How can you find a string within a string?
8. Q: how to secure a partition with LINUX
9. Riddle me this - when is a ksh string not a string?
10. search string in other string
11. how to substitute strings within a string buffer efficiently?
12. quoted strings within quoted strings
13. search string bbb in block b after string aaa found in block a