D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Waiting for keyboard input in a shell script

 

On Friday 25 November 2005 8:34 pm, Rob Beard wrote:
> The bit of code I'm stuck on is:
>
>     ls | grep -i cpio | while read fn; do

That looks borked to me.

while read fn
echo $fn
done

works fine.

Why are you piping the output of grep to while?

ls outputs to grep which outputs text. This text should be passed to the if, 
not to the while.

My version would be:

fn=`ls | grep -i txt`
if [ ! `echo "$fn" | grep -i last` ]
  then
        echo
        echo "Please insert a blank disc in your CD/DVD writer and press
RETURN"
        echo "to commence writing disc $diskcount of the backup set."
        echo
fi
read first

You could specify a prompt using read:
read -p "Only return is needed" first

$ bash t

Please insert a blank disc in your CD/DVD writer and press
RETURN
to commence writing disc  of the backup set.

Only return is needed
$

You aren't expecting input here (I assume), just a keypress so the value of 
the read isn't useful?

> Now the problem I'm having is with the read command which is just before
> command used to burn the CD.  I've tried using 'read' and I've even
> tried writing a very basic C program which just executes getchar() but
> none of the commands seem to work, they just appear to be ignored.

Because it's being expected to react to the pipe.

-- 

Neil Williams
=============
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/

Attachment: pgpXYHzlZRvo2.pgp
Description: PGP signature