Alexander Mills Alexander Mills - 1 year ago 77
Bash Question

Get time diff in tenths of seconds

Just trying to keep track of the build time for a bash script, to the 1/10th of a second

I am looking for something like:

START_TIME=date()
sleep 5;
END_TIME=date()-START_TIME;


and round it to a tenth of a second.

How can I do this?

123 123
Answer Source

You can use date with nanosecond and truncate to one char

#!/bin/bash

START=$(date "+%s%1N")
sleep 2
END=$(date "+%s%1N")

echo "The difference is $((END-START))"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download