Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-20-2006, 10:54 PM   #1
Registered: May 2006
Posts: 55

Rep: Reputation: 15
string comparision

Hi friends,

I have a string variable in shell script as :

echo $str
Five-time Olympic champion Ian Thorpe retired from competitive swimming on Tuesday at the age of 24, saying breaking records had lost its allure.


Now I want to check whether the word "from" (case insensitive) exists or not in the above string variable $str. I want to get TRUE or FALSE condition checking.

How to do it in shell script?

Last edited by Fond_of_Opensource; 11-21-2006 at 12:45 AM.
Old 11-21-2006, 02:47 AM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,041
Blog Entries: 11

Rep: Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907
echo $str|grep -i from >/dev/null 2>&1
and check $? afterwards ... 0 is true, 1 is false.

Old 11-21-2006, 03:02 AM   #3
LQ Newbie
Registered: Aug 2006
Location: Beijing China
Distribution: RedFlag
Posts: 6

Rep: Reputation: 0
using this may be better: echo $test|grep -iE '\<from\>'


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
9.0 - 10.1 official comparision Nau Mandriva 1 04-11-2005 09:08 AM
comparision Ammad Linux - Networking 1 03-10-2005 05:26 AM
A picture comparision program? vmicho Linux - Software 3 10-27-2004 12:47 PM
Proper GLX Gears Comparision otchie1 Linux - Hardware 9 10-08-2004 07:46 AM
string comparision in linux scripts rm1 Programming 7 09-20-2004 11:25 AM

All times are GMT -5. The time now is 01:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration