help with bash script

Tony Arnold tony.arnold at manchester.ac.uk
Tue Jul 21 22:37:06 UTC 2009



Rashkae wrote:
> R Kimber wrote:
>> I'm trying to do something very simple but failing, and would appreciate
>> some pointers.
>>
>> I'm trying to create a script that executes a command on a series of files
>> one-at-a-time, pausing between each execution.  The input files are all in a
>> single file, one on each line. I have
>> .......................
>> #!/bin/bash
>> cd <to working directory>
>> cat <file with list of input files> | while read FILECHECKED do
>>
>>    <command> "$FILECHECKED"
>>    echo
>>    RESPONSE="Z"
>>    echo -n Press a key to continue....
>>    while [ "$RESPONSE" = "Z" ]
>>    do
>>       read RESPONSE
>>    done
>>    echo
>> done
>> ......................
>>
>> The command executes, but there is no pause between the processing of each
>> input file.  I've tried various variations using the read command, to no
>> avail.  Curiously, if I add
>> echo "$FILECHECKED" and "$RESPONSE"
>> just before the final 'done', it prints out the name of the file it has
>> just processed and the file it is about to process - not 'Z'.
>>
>> I'm obviously doing something stupid.
>>
> 
> I'm not at all sure how I would go about doing what you are trying to
> do, but I can tell you why your script is gone awry
> 
> The stdout from the cat command is getting picked up by the inner loop
> read command, therefore, the current script is only doing it's operation
> on every other file.

Try changing the read RESPONSE line to:

  read RESPONSE < /dev/tty

Regards,
Tony.
-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 870 136 1004
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: tony.arnold at manchester.ac.uk




More information about the ubuntu-users mailing list