[ale] bash function to show elapsed time

Raj Wurttemberg rajaw at c64.us
Mon Nov 17 13:56:05 EST 2014


Ahh.. That's kinda cool.  I'll have to make note of this.  Thanks!

(I'm still a noob at bash scripting)

/Raj

> -----Original Message-----
> From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of
> Todor Fassl
> Sent: Monday, November 17, 2014 12:33 PM
> To: ale >> Atlanta Linux Enthusiasts
> Subject: [ale] bash function to show elapsed time
> 
> I thought I'd share a bash function I wrote this morning. It displays
elapsed
> time in hours, minutes, & seconds. You call it like this:
> 
> elapsed 0
> [do something]
> elapsed
> [do something else]
> elapsed
> 
> You canreset the start time by passing it any value as the first
parameter. I
> used zero in the example above because it looks a little more clear. You
could
> just as easily use "elapsed reset" or "elapsed start".
> 
> The function:
> 
> function elapsed
> 	{
> 	if [ -z "$t1" -o ! -z "$1" ]; then
> 		t1=`date +"%s"`
> 	else
> 		t2=`date +"%s"`
> 		diff=$((t2-t1))
> 		hours=$((diff/3600))
> 		diff=$((diff-(hours*3600)))
> 		mins=$((diff/60))
> 		secs=$((diff-(mins*60)))
> 		printf "Elapsed %02d:%02d:%02d\n" $hours $mins $secs
> 	fi
> 	}
> 
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo



More information about the Ale mailing list