I want to read a file using shell script and here want to calculate the time required to read a file. I have created below method to get the time in milliseconds at the start and end of the file reading and I will calculate the time difference, but it is not adding the hour+minute+seconds and showing me that the required numeric input.
Method
getCurrentTimeInMili()
{
hourTime=$(($(date +%H)*3600))
minuteTime=$(($(date +%m)*60))
secondTime=$(date +%S)
timeInMili= $(($hourTime + $minuteTime + $secondTime));
return timeInMili
}
Error
./testshell.sh: line 17: return: timeInMili: numeric argument required
Invoking
datemultiple times means that their return values can be a bit out of sync with each other — which could be bad if we’re invoked just before a second boundary. Better is to call date only once and retrieve all the information desired, like so:If you don’t need this much accuracy, you can simply use the
timebuiltin, as in: