TimeDiff function?

Hi,
Is there any function in Unix that could get the Time Differrence of two values? this would be used as statistic for how long a job completes, from start to finish..

Please help.

thanks,
Jet

# time find / -name host*
....
....
....

real 0m12.63s
user 0m1.82s
sys 0m8.44s

#

Thanks..
Could you explain what the code do?

time <some command> - does what you want, return elapsed times
find / -name 'host*' - searches for all filenames on the system that start with "host"

Is there any way to find a execution time of a shell script which have number of commands?

If you're asking what I think you are, it's time ./shell-script.sh

Or if you're asking for something that tells how many commands the shell script has executed, only the shell script knows.

Thanks for your reply. i know this time command but i need to make it in that shell script only.Like if shell script have n number of commands then need time as sum of time taken by all the commands.any help would be appreciated.

In that shell script only? Like this?

#!/bin/sh
exec time ./other-script.sh "$@"

If that's not it, could you please be more specific with your question?

Lets say there is a shell script(abcd.sh) which have 10 commands, i need to get the execution time of this shell script.And we can not run it as

time ./shell-script.sh

and this time command logic needs to be in the shell script(abcd.sh) itself.So basically what i need is time(comm1+comm2+comm3..........comm10).shell script is

x="0000000000.000"
echo "KEY               - Value"
echo '----------------------------------'
while read line
do
y=`echo "$line" | awk '{ print substr( $0, 125, 14 ) }'`

if [ "$x" = "$y" ]
then
key=`echo "$line" | awk '{ print substr($0, 20, 17) }'`
echo "$key - $y"
fi
done < seg1.txt

You can get the execution time of the script the same way we've been telling you all along. I do not see why my solution would not work exactly the way you want it to -- make the script you're calling a stub that calls the real script with 'time'.

You do not need to call 'time' for each individual process when all you need is the execution time, not the user or system time; the overhead of calling 'time' for each individual program would start adding up, as well.

if you are using ksh, there is a built-in variable called $SECONDS you can use.
It is ZERO from the start. Just echo $SECONDS at the end of the script.

Thanks corona and izy for your solutions.Both solutions are working.

time $(
command1
commad2
command3)

# or
time ` command1
command2
command3`