Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Aug 2003 11:53:13 -0500
From:      Stephen Hilton <nospam@hiltonbsd.com>
To:        "Charles Howse" <chowse@charter.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Using bc in bash script
Message-ID:  <20030814115313.2707cb21.nospam@hiltonbsd.com>
In-Reply-To: <001a01c3627e$487d7a10$04fea8c0@moe>
References:  <20030814154920.GA74582@users.munk.nu> <001a01c3627e$487d7a10$04fea8c0@moe>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 14 Aug 2003 11:08:21 -0500
"Charles Howse" <chowse@charter.net> wrote:

> > On Thu, Aug 14, 2003 at 10:46:45AM -0500, Charles Howse wrote:
> > > Hello List,
> > > 
> > > I've migrated from Redhat Linux 9 to FreeBSD 4.8-RELEASE, 
> > character mode
> > > - no gui.
> > > 
> > > I'm trying to calculate the number of seconds between 
> > $start_time and
> > > $end_time in a bash script.
> > > 
> > > Start_time=`date +%s` # Seconds past midnight at start of script
> > > [ do lots of stuff ]
> > > End_time=`date +%s`   # Seconds past midnight at end of script
> > > 
> > > Then I want to: et=`bc $end_time - $start_time` to get the number of
> > > seconds or fractions of seconds elapsed.
> > How about:
> > 
> > et=`echo "$end_time - $start_time" | bc`
> 
> Hi Jez, thanks for the reply!
> 
> As my daughter would say, "Well, DUHHHHHHH!"
> That worked fine, it reported 0 seconds.
> Can I refine it to give me something like: .784 seconds?

Charles,

This will set bc precision to 5 decimal places:

et=`echo "scale=5 ; $end_time - $start_time" | bc`


Regards,

Stephen Hilton
nospam@hiltonbsd.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030814115313.2707cb21.nospam>