Your test whether a value is in the result is to blame because in case you search for name-1
in a result containing name-1-new
you will find it, so your program will act as if the $opt1
is in the result.
If you can, choose names for those opt
s which cannot be mistaken for one another. That would be the easy "poor-man's" approach but it might suite you.
A better way would be to search for the delimiters along with the values:
[[ :$response: = *:$opt1:* ]] && echo "$opt1" >> file.txt
etc. In any case make sure that delimiter cannot be part of the values of course.