I have a sentence which is nothing but a string variable with words separated by spaces .
I have another variable which contains a word . What I wanted is to find exact matching of the word in the variable containing the sentence . I have tried this :
read -p "enter the word to match " STR # STR contains VVDNSG
#this DUP_SG_NAME_PUBLIC variable contains a string which consists of few words
DUP_SG_NAME_PUBLIC=$(aws ec2 describe-security-groups \
--query 'SecurityGroups[*].{GroupName:GroupName}' \
--output text)
if [[ $DUP_SG_NAME_PUBLIC =~ $STR ]]
then
echo "true"
else
echo "false"
fi
Problem Here I have provided "VVDN" as string but I have to match "VVDNSG" but this code works for both . Even for VVDN and VVDNSG which is understandable .
What I want to do
I want to find exact match that is if given VVDNSG as STR value it should print true or else false even with VVDN and I want that to do the comparison with variables not with literal strings .
I have tried few examples googling most of them either tell you to find match in a file or hardcode the string comparison.
casewith an exact match first and a wildcard match second might be what you want.