Using bc in bash script

Charles Howse chowse at charter.net
Thu Aug 14 11:36:06 PDT 2003


> > > Sorry I jumped the gun there, the scale is needed for 
> this to work 

Not a problem, thanks for working with me!

> > The precision is in hundredths of a second as I understand it from
> > playing with time(!):
> > 
> > #!/bin/sh
> > time_file=tmp.time
> > time="time -a -o $time_file"
> > $time cat /var/log/messages >/dev/null 2>&1
> > $time cat /var/log/maillog >/dev/null 2>&1
> > awk '{sum+=$1}END{print sum}' $time_file
> > rm $time_file
> > 
> > which outputs:
> > 
> > [18:34:03] munk at users /home/munk# sh tmp.sh
> > 0.01
> > 
> > This simple script just times each cat command and appends 
> the output from
> > time to the $time_file, then prints out the sum of the 
> first columns of
> > the time outputs found in the time file. 
> > 
> > Just an idea.
> > -- 
> 
> Jez,
> 
> Your shell script works fine for me, resolving to 100th's of a second.
> 
> Looks like a good answer for Charles :-)
> 
> I still am wondering why the date command does not have a format 
> string for seconds (down to 100th's) like "+%ss" and also why 
> the time command stops at 100th's when other programs resolve 
> time to 5 or 6 decimal places ?
> 
> Thanks for sharing the info,

Yes, thanks very much!
I'll try that as soon as I finish my break from hanging window blinds
for my daughter. (ick!)




More information about the freebsd-questions mailing list