Computing.Net > Forums > Unix > detect a char in a string (ksh)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

detect a char in a string (ksh)

Reply to Message Icon

Name: MMMMMM
Date: April 23, 2003 at 07:21:47 Pacific
OS: AIX
CPU/Ram: 9854333
Comment:

Hello,

I try to detect the presence of a char in a string. This is korn shell.

mystring="1234-"
mychar="-"
if [ mystring includes mychar ] ; then
exist=1
else
exist=0
fi

What should I write instead of [ mystrinf includes mychar ] ? Thanx !!

M



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: April 23, 2003 at 12:59:24 Pacific
Reply:

Here's one way ...

mystring="1234-"
mychar="-"

if [ $(expr "$mystring" : ".*-") -gt 0 ] ; then
   exist=1
else
   exist=0
fi


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: detect a char in a string (ksh)

count the occurence of a char in a string www.computing.net/answers/unix/count-the-occurence-of-a-char-in-a-string/8516.html

How to attach a file in a mail (UNIX script) www.computing.net/answers/unix/how-to-attach-a-file-in-a-mail-unix-script/8487.html

replacing newline char in a text in www.computing.net/answers/unix/replacing-newline-char-in-a-text-in/7673.html