Calculate duration in seconds in bash
Hi,
I would like to subtract the end time with a start time in bash. How can I do it? Here's a script of example of what I want: startdate = GETTIME ls -la enddate = GETTIME echo "DURATION: $enddate-$startdate seconds." |
Code:
echo "DURATION: $((enddate-startdate)) seconds." |
But how do I get the time in bash?
|
Oh! :)
Probably you want to use the `date` command. For example, to print the UNIX time, do: Code:
sasha@reactor: date +%s Code:
VARIABLE=$(date +%s) |
Oh hey, P.S.: I notice you are saying "OS: Free BSD" in your signature or under your post, but you are posting from an Ubuntu-type of OS. You may want to specify which this question applies to (and specify in any thread you create), and or change your signature accordingly so as to lessen the chance of confusion.
Cheers. |
Open your favorite browser, go to www.google.com/linux, and search for "measuring run times". You will find a wealth of information to read on the subject, probably with sample code in many of them.
|
I made this script, but it's is not working, why? (I'm newbie in bash)
#!bin/bash START=date +%s sleep 2 END=date +%s echo "DURATION: $(END-START)" |
A lot of proofreading needed:
Code:
#!/bin/bash |
It worked. Thanks.
|
All times are GMT -5. The time now is 03:03 AM. |