how to input answer (enter) if output contains a string?

how to wrote a script that reads an input from the reader (dir name) and then answer yes to all questions in the script unless the answer to any of the questions contains a certain string?

example:

$] script.sh dir_name
$] question_1: (answer should be y right after the question is echoed, ie. I do not have to type it)
$] question_2:
if the above output contains a string "THIS IS STRING"
then the answer should be "Enter" otherwise it should be y

$ script.sh dir_name
$ is this a dir? (question 1)
$ y
$ yes this is a good dir (output after answering with y)
$ Does it have txt files? (question 2)
$ [enter] - if the above answer contains "good", or "y" if the above answer does not contain "good"

Please help me with this piece of script.

thanks

---------- Post updated at 05:35 AM ---------- Previous update was at 05:20 AM ----------

So I think I need to know how to assign the output to a variable and then grep the variable to see if it contains "good" in it.
But how to make all answers y unless the output has "good" is my problem :frowning:

You might want to learn about expect.

I hope this helps.

bakunin

Thanks for the answer.
I am not sure what expect is, I will see it now.
But I think what I need is to check the output of the command (I called it question) to see if it contains a certain string, STRING, or not. How to check the output of a command to see if it contains a string is my problem now. I am googling about it, but no answers yet!

Again: have a look at expect. You might want to first check the abilities of a tool and only then disregard it as unsuitable for your purposes, not the other way round.

bakunin