I have a question concerning string functions. I have not been able to locate a function that does what I want, so I fugured I'd ask before I wrote on myself.
Is there a function to which I can pass 2 strings (character string a and character string b) and have it tell me if string b appears anywhere in string a?
ie, can it determine if "test" exists in the string "this is a test"?
grep will do what you want. If you just want a "yes it exists" or "no it doesn't" answer, just check $? after you have done the grep. This example might help :
stringa=test
stringb="this is a test"
echo $stringb | grep $stringa >> /dev/null
if [ $? = 0 ]
then
echo "Match Found"
else
echo "No Match Found"
fi
I assume the original poster choose to post on the C programming forum, he/she may want an answer with the C programming language, not shell script.
Try the strstr() function.
From the man page of string.h functions:
#include <string.h>
char *strstr(const char *s1, const char *s2);
strstr()
The strstr() function locates the first occurrence of the
string s2 (excluding the terminating null character) in
string s1 and returns a pointer to the located string, or a
null pointer if the string is not found. If s2 points to a
string with zero length (that is, the string ""), the func-
tion returns s1.