Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 03-08-2007, 12:35 AM   #1
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
# 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"
and so you understand what is being contained within depend it will normally be declared like:


doc? (dev-java/taglibrarydoc)

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
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

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


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 05:09 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