Calculating script run time in Solaris OS

Hi All,

I have written script and wanted to know the run time of it in seconds. i used below logic but am not getting the results in second instead getting error.

cat pkloader.sh

# if you want to calculate the time in milliseconds then use $(date +%s%N)
START_TIME=`date +%s`
echo "$START_TIME"

##### logic #######

echo "pkloader execution has completed"
END_TIME=`date +%s`
echo "$END_TIME"
DIFF=$(( $END_TIME - $START_TIME ))
echo "Script took $DIFF seconds to complete"

Error am getting when running the script :

./pkloader.sh: line 33: %s - %s : syntax error: operand expected (error token is "%s - %s ")

and observed that on line to print START_TIME and END_TIME , i get just %s as output.

this script running in SunOS

Your script works fine on my ubuntu.
PS I do not see the hash bang in your script #!/bin/bash

If you do not need DIFF in a variable

cat pkloader.sh

# if you want to calculate the time in milliseconds then use $(date +%s%N)
START_TIME=$(date +%s)
echo "$START_TIME"

##### logic #######

echo "pkloader execution has completed"
echo "Script took $(( $(date +%s) - $START_TIME )) seconds to complete"

Just check the man page in your OS whether its %s or %S