Unix Shell - Displaying questions form a file and reading the user input

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2005 > Displaying questions form a file and reading the user input





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Displaying questions form a file and reading the user input
k.balamurugan@gmail.com

2005-11-13, 5:53 pm

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.

Janis Papanagnou

2005-11-13, 5:53 pm

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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com