Re: Displaying questions form a file and reading the user input

From: Janis Papanagnou (Janis_Papanagnou_at_hotmail.com)
Date: 11/13/05


Date: Sun, 13 Nov 2005 20:59:20 +0100

k.balamurugan@gmail.com wrote:
> I have following script
>
> #!/bin/sh
> #set -x
> #
>
> cat $newParamListFile | grep "^$1" |
> while read line
> do
> paramQ=`echo $line | cut -f4 -d':'`
> echo $paramQ
> read ans
> echo $ans
> done < ./newparams.list
>
> the newparams.list contains following data
>
> fiel 1:param1:param value1:Question1
> file 1:param2:param value2:Question2
>
> fiel 2:param1:param value1:Question1
> fiel 2:param2:param value2:Question2
>
> When the script invoked as follows
> ./scriptfile file1
> I want to display the Questions corresponding to file1 one by one and
> get the answer from the user. The second read is causing the problem it
> doesnt wait for user input. It reads Question2 and displays.
>
> Is there any other way I can acchive what I want.
>
> Note: I wanted to use only /bin/sh only for backward compatibility
> reasons.
>
> --Thanks,
> Balamurugan.
>

Try something like this...

while IFS=: read f p v q
do
     if [ x"$f" = x"$1" ]
     then
         echo "$q"
         read ans </dev/tty
         echo "$ans"
     fi
done <newparams.list

Janis



Relevant Pages