[plug] script

Anthony J. Breeds-Taurima tony at cantech.net.au
Mon Aug 5 10:01:06 WST 2002


On Sun, 4 Aug 2002, Jon Miller wrote:

> 
> Like to know how do I go about adding a new line to a file (is it using \n
> on the last input?) where information is being written to.  In other words
> the script prompts for information and once it gets to the end of that 
> record" I need it to start on the next line in the "result" file and record
> the next record.  It needs to do this until the data input is completed. 
> What I have to do is create a do-while to let the program know how many
> records are being inputted.  Once this is completed, it needs to "write or
> close the result file with the number of records recorded.

Don't really understand the problem so I'll punt in the dark:

-------
#!/bin/bash

TMPFILE=`mktemp -q /tmp/$0.XXXXXX`
if [ $? -ne 0 ]; then
        echo "$0: Can't create temp file, exiting..."
        exit 1
fi


echo -n " Enter number of records to input: "
read recnum

i=0
while [ $i != $recnum ] ; do
        echo -n "Record $i : "
        read record
        echo $record >> $TMPFILE
        i=$[ $i + 1 ]
done

cat $TMPFILE >> /path/to/data_file
rm $TMPFILE
-------

Yours Tony

   Jan 22-25 2003           Linux.Conf.AU            http://linux.conf.au/
		  The Australian Linux Technical Conference!



More information about the plug mailing list