If value in varA is not in varB then do something


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If value in varA is not in varB then do something
# 1  
Old 04-16-2010
If value in varA is not in varB then do something

Basically what I need to do, is read the value of varA, and if it's in varB, then do something, if not, do something else.
varA will contain a single string like:


Code:
proj_choice="Test"

Code:
test_var="ABC Test blah foobar etc"


So if the value of proj_choice is contained in test_var, do something if not do something else:
# 2  
Old 04-16-2010
One approach is to use grep command

Code:
#!/bin/ksh

proj_choice="Test"
test_var="ABC Test blah foobar etc"
echo $test_var | grep $proj_choice > /dev/null 2>&1
ret_val=$?

if [ $ret_val -eq 0 ]
then
 echo "Found"
else
 echo "Not Found"
fi

# 3  
Old 04-16-2010
if echo 123 | grep -q 2; then echo ok; fi
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question