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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to input answer (enter) if output contains a string?
# 1  
Old 12-02-2010
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

Code:
$ 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 Smilie
# 2  
Old 12-02-2010
You might want to learn about expect.

I hope this helps.

bakunin
# 3  
Old 12-02-2010
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!
# 4  
Old 12-02-2010
Quote:
Originally Posted by faizlo
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.
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automatically enter input in command line

Hi, This is a script which to create an opvn user, I want which answer automatically to a certain part so, I try this, it works without the red part but I must type manually.. : #!/bin/bash ## Environnement ## LC_ALL=C ## Paths ## rsa_dir="etc/openvpn/easy-rsa"... (10 Replies)
Discussion started by: Arnaudh78
10 Replies

2. Shell Programming and Scripting

View on screen text file and enter input

Is the below correct syntax for if the user enters something other than "GJB2 or MECP2, or PHOX2B", then they are shown on the screen format.txt and allowed to enter in one of those formats? Thank you :). Basically, the user can see which formats are allowed and enter a variant while viewing... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value File 1 export SERVER_CONNECTION=//dvlna002:10001/SmartServer File2 export SERVER_CONNECTION=///SmartServer File3 export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

4. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

5. Shell Programming and Scripting

Enter an input and reference another line in ksh script

Hi I have a file like so: Code: Frank Peter Tony Robert Mike 1 2 3 4 5 5 4 2 3 1 4 3 1 5 2 My out should look like this: Peter Tony Mike and so on.... I have the first part done to ask the user to... (8 Replies)
Discussion started by: bombcan1
8 Replies

6. Shell Programming and Scripting

enter key or carriage return as input in perl

hi experts Question in perl i'm creating a script to take from user a different inputs one of them is the carriage return .. so that i want to make an if condition if the user hit enter key the user will go to previous step it something like that chomp ($input = <STDIN>); if ($input =~... (3 Replies)
Discussion started by: doubando
3 Replies

7. Shell Programming and Scripting

using read to enter the input at runtime

Hi I am stucked in the below script .I want to input with yes/no from the user and then execute the code inside if but it is not working .I just need the logic as where I am wrong so that i can use the same in my work . then echo "Hi All" fi ]. Please suugest . (4 Replies)
Discussion started by: mani_isha
4 Replies

8. Shell Programming and Scripting

redirect an awk string output to a script input with pipes

Hi, I have a function in a bash script that returns a string after some operations using awk. The following code returns 555 $VARIABLE="EXAMPLE" get_number $VARIABLE this value I'd like to pass it as a second argument of another script with the following usage myscript.sh <param1>... (7 Replies)
Discussion started by: rid
7 Replies

9. Shell Programming and Scripting

Input from a file and converting the answer

Hello all, I am new to unix and i am having probelms. If anyone could help. I am trying to input numbers from a file called data.file The problem i am having is I can input the file but when I hit enter to get the answer onto my output file i get a error message (standard_in) 1: parse error. ... (3 Replies)
Discussion started by: nfsrider
3 Replies

10. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies
Login or Register to Ask a Question