Shell script date calculations

by Ron on June 23, 2008


#!/bin/sh
before="$(date +%s)"
echo $before
sleep 5
Ymd="$(date '+%Y%m%d')"
echo $Ymd
after="$(date +%s)"
echo $after
elapsed_seconds="$(expr $after - $before)"
echo Elapsed time for code block: $elapsed_seconds

Bookmark and Share

{ 1 comment… read it below or add one }

Jadu 07.20.08 at 10:51 am

Nice site.

A different look of the expr line.

((elapsed_seconds=after - before))

//Jadu, http://unstableme.blogspot.com

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>