On Wed, 05 Jul 2000,  Strandell, Ralf wrote about,  problem: input redirection in a 
loop:
> Hi
> 
> I need some help with scripts. I'm using the following loop:
> 
>       while read line
>       do
>               # manipulate file here
>       
>               if [ "$test" = "true" ]
>               then
>                       echo "Would you like to read more lines?" ; read
> input
>                       # process input here (continue or exit )
>               fi
> 
>       done < "$filename"
> 
> The problem is that this reads ALL input from file.
> 
> How do I make this loop able to read from user as well?
> The following does not work. Why?
> 
>       exec &4<"$filename"
>       while read line
>       do
>       # ...
>       done <&4

Loops are funny things, or they can do funny things from time to time.

You did not include the most important parts of the script, however, i
would use somthng like;

echo -n " Read more lines,? [Y/n]: "; read answer
if [ "$answer" = "Y" -o "$answer" = "y" -o "$answer" = "" ]; then
        # do your stuff here
else
        echo "Exiting..."
        exit 1
fi

The above allows for upper and lower case, the -o "" allows for a C/R and
assumes "Y".

Anyway as i see it it is beter just to use the program "more" or program
"less" in a script.

>       
> Ralf

-- 
Regards Richard
[EMAIL PROTECTED]
http://people.zeelandnet.nl/pa3gcu/


-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs

Reply via email to