How do you tell if a string contains another string in Unix shell scripting?
- by Matt
Hi all,
I want to write a Unix shell script that will do various logic if there is a string inside of another string. For example, if I am in a certain folder, branch off. Could someone please tell me how to accomplish this? If possible I would like to make this not shell specific (i.e. not bash only) but if there's no other way I can make do with that.
#!/bin/sh
CURRENT_DIR=`pwd`
if [ CURRENT_DIR contains "String1" ]
then
echo "String1 present"
elif [ CURRENT_DIR contains "String1" ]
then
echo "String2 present"
else
echo "Else"
fi