LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-08-2007, 12:35 AM   #1
ali_bush
LQ Newbie
 
Registered: Mar 2007
Posts: 1

Rep: Reputation: 0
Question bash: test for substring inside string


Hi im trying to write a bash script that checks whether a parameter to a function is contained within a global variable DEPEND


so basically Ive attempted to do the following and similar
Code:
# for this example do stuff to ${1} and store in variable
# actual code just reg expresses out the actual part I require
# and works perfectly
# variable will contain values such as ant-core, cos, taglibrarydoc, javacc, jsr123
# etc etc
if [[ "${DEPEND}" == *${variable}* ]]; then
   echo "here2"
fi
and so you understand what is being contained within depend it will normally be declared like:

CDEPEND=">=virtual/jdk-1.5"

DEPEND=">=dev-java/cos-1.1.1
>=dev-java/ant-core-1.7
=dev-java/something-1.1-r1
doc? (dev-java/taglibrarydoc)
${CDEPEND}"

does anyone have any ideas. This function has to be robust to spaces and other special characters.
 
Old 03-08-2007, 05:34 PM   #2
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
This might work:
Code:
ada@barnabas:~> match="string"
ada@barnabas:~> (a="some strong content"; [[ "$a" =~ "${match}" ]] && echo "matched" )
ada@barnabas:~> (a="some string content"; [[ "$a" =~ "${match}" ]] && echo "matched" )
matched
 
  


Reply

Tags
bash, programming, string


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash replace all matches of regex substring in string nickleus Linux - General 3 04-30-2011 12:08 PM
extract substring from string in C baddah Programming 6 02-02-2010 05:22 AM
replace a substring with another string in C zeppelin Programming 21 11-09-2009 10:59 PM
how many occurances of a substring are they n a string linuxmandrake Programming 1 04-11-2006 03:02 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 02:39 PM


All times are GMT -5. The time now is 06:08 AM.

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