Perl script give answers by file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script give answers by file
# 1  
Old 11-27-2013
Perl script give answers by file

Hi,

I am new in perl.

I am running a perl installation script, its asking for paths and so many inputs.

Can we provide that info by any file.
so i can avoid the interactive installation.
# 2  
Old 11-27-2013
If you know exactly what questions it will ask, you could put the answers in a file, and then pipe it to the script.

For example:

Code:
$ cat myScript
printf "Type y to continue: "
read ans
if [ "$ans" != y ]; then
  echo Exiting.
  exit 0
fi

printf "Type a number: "
read num

printf "Enter the default bin path: "
read path

echo
echo "You entered the number: $num"
echo "You entered the path: $path"

$ cat answers.txt 
y
33
/usr/bin

$ cat answers.txt | ./myScript
Type y to continue: Type a number: Enter the default bin path: 
You entered the number: 33
You entered the path: /usr/bin

Otherwise, there's always expect.
# 3  
Old 11-27-2013
Assuming that "config.file" contains the answers in the following format:
Code:
question1=answer1
question2=answer2
...

you can try something like this:
Code:
my %config;
open (my $fh, "config.file");
while (chomp(my $line=<$fh>)) {
  my @fields = split /=/, $line;
  $config{$fields[0]}=$fields[1];
}

Then you can access those answers like this:
Code:
$config{question1}
$config{question2}

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need optimized awk/perl/shell to give the statistics for the Large delimited file

I have a file size is around 24 G with 14 columns, delimiter with "|" My requirement- can anyone provide me the fastest and best to get the below results Number of records of the file First column and second Column- Unique counts Thanks for your time Karti ------ Post updated at... (3 Replies)
Discussion started by: kartikirans
3 Replies

2. Shell Programming and Scripting

Bash script to give multiple choices and a varying number of answers

Hello everybody, I use `case' quite a lot but , excellent as it is , it only gives one final result ; can anyone suggest a way whereas , say long lists of choices are given and I , or a user could select either one two or any number of results to be echoed . many thanks in... (3 Replies)
Discussion started by: V686
3 Replies

3. Shell Programming and Scripting

Select answers from multiple questions using shell script

I have a text file in this format Some lines.... Question no: 1 The question? A. Answer 1 B. Answer 2 C. Answer 3 D. Answer 4 Answer:B Some lines.... Question no: 2 The question? (choose 2) (10 Replies)
Discussion started by: zorrox
10 Replies

4. Shell Programming and Scripting

Interactive shell - Give answers to shell

Hi, I have a script that calles some other scripts. Those scripts are expecting some inputs. Right no I am typing manually. But now the number of questions from other scripts are too much and I want to give asnwers autimatically. example. Other scripts gives me 2 options 1) joom... (2 Replies)
Discussion started by: microsim
2 Replies

5. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

6. Solaris

Please give answers for this interview questions

I was not able to get answers for these interview questions. It will be appreciable and useful if any one answers this questions. (5 Replies)
Discussion started by: Sesha
5 Replies

7. Shell Programming and Scripting

Give input to a perl script while execution

Hi, I have a perl script which prints me the epoch value of a specific date and time given.Now I want to proceed to a next step ie i want to give the input at the time of execution. I have to initialise the date and time values in the script before executing it.But now i want to give the date... (3 Replies)
Discussion started by: jyothi_wipro
3 Replies

8. Shell Programming and Scripting

source a property file in script give error

I have sourced a property file in my script like this to load some variables in the script Then i am able to echo all the property file values inside script but the script is not able to recognize other unix commands #!/bin/bash . build.properties mkdir build i am getting error ... (3 Replies)
Discussion started by: codeman007
3 Replies

9. Shell Programming and Scripting

basic script for yes and no answers

What is the basic syntax for a script that says do you want to do this? y - execute this n - end not y or n - end and print this for example if I want to run this: "Do you want to start this process?" answer if y,Y, or yes then run the following script (do I put the script with... (10 Replies)
Discussion started by: llsmr777
10 Replies
Login or Register to Ask a Question