Hi People,

        In a bash script how would I append information to the start of
the file instead of the end?

Background:
        I've written a couple of scripts to time how long I am on the
internet (I'm one of these unfortunates who have to pay by hour :( ) and a
further script to test the total time for the month that I run before I
log on (to stop me from spending too much $$$).

        The problem I'm having is with the script to test the total time
for the month.  An excerpt follows...

------------Begin Script Excerpt-------------------
TIMES_UP=$(bc -q /etc/ppp/logs/prog-tot < /etc/ppp/logs/q)
if [ $TIMES_UP -ge 180000 ]; then
echo "You have already used up at least 50 hours this month"
echo -n "Are You Sure That You Want To Continue? (Y/N): "
read ANSWER
        if [ $ANSWER = "N" -o $ANSWER = "n" ]; then
        echo "Probably a good move - time is money"
        exit 0
        else echo "Well it's your money!"
        fi
fi
------------End Script Excerpt-----------------------

        The file /etc/ppp/logs/q just contains the word "quit" to exit
from bc.

        The file /etc/ppp/logs/prog-tot is created from the script I use
to turn the timer off, with the line...
        echo -n "+"$TIME_ELAPSED >> /etc/ppp/logs/prog-tot
This file starts life with "0" in it.

        The problem is with "-n" in the echo line, bc doesn't like it at
all (gives a parse error because there is no end of line character).  So
if I initialized prog-tot with echo "0" > prog-tot (no -n) and then
_inserted_ $TIME_ELAPSED"+" before the "0" instead of _appending_ 
"+"$TIME_ELAPSED after it everything would be honky-dory. But how???


Regards, Steve Youngs <[EMAIL PROTECTED]>   ICQ: 34307457
----------------------------------------------------------
|                                __                      |
|Isn't it good to know that     / /   __ ___  __ ____  __|
|There _IS_ an alternative!    / /__ / // _ \/ // /\ \/ /|
|                             /____//_//_//_/\_,_/ /_/\_\|
----------------------------------------------------------
Data to Picard: No I do NOT run Windows!

Reply via email to