Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 4
    I didn't want to throw away the output from the command though. So I guess your third code block is closest to what I had in mind. Although I'd write the last one as DIFF=$((END-START)), making use of the arithmetic expressions. :) ... thanks for the answer. +1 Commented Apr 26, 2011 at 20:00
  • 2
    @STATUS_ACCESS_DENIED: Bash doesn't do floating point arithmetic, so if you want better than second resolution (.%N in binfalse's code), you either need bc or fancier calculations. Commented Apr 26, 2011 at 21:11
  • @Gilles: I know. As I wrote in my question integers are fine. No need to have a higher resolution than second. But thanks, the date invocation would have to be changed. I had realized that, though. Commented Apr 26, 2011 at 23:25
  • 11
    FYI, the date formatting %N doesn't seem to work on Mac OS X, it just returns "N". Ok on Ubuntu. Commented Oct 19, 2015 at 21:24
  • 1
    If you find yourself in a situation where there's dc but no bc (probably rare but I just did), you can use DIFF=$(echo "$END $START - p" | dc). Commented Oct 2, 2018 at 12:42