Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement

Status
Not open for further replies.

simpson

MIS
Joined
Oct 23, 2001
Messages
58
Location
CA
I would like to create an if statment that will evaluation if a variable contains a sequence. ie. does vairable 'var_a' contain 'abc' I am kind of confused as to how I would approace this.
Thanks
 
Look at expr - for example
Code:
if expr "$var" : ".*test_string.*" >/dev/null
then
  echo $var contains 'test_string'
fi
alternatively you can use a case statement
Code:
case $var in
  *test_string*) echo var contains test_string;;
esac

Ceci n'est pas une signature
Columb Healy
 
Thank you so much, this worked perfectly... Greatly appreciated.
 
Hi

Alternatively :
Code:
if [[ "$var_a" = *test_string* ]]
then
  echo $var contains 'test_string'
fi
Tested with [tt]bash[/tt] and [tt]ksh[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top