Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:50:39+00:00 2026-06-04T10:50:39+00:00

I want to read a file using shell script and here want to calculate

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:50:41+00:00Added an answer on June 4, 2026 at 10:50 am

    Invoking date multiple 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:

    getCurrentTimeInMili() {
      date +'%H 3600 * %M 60 * + %S + 1000 * %N 1000000 / + p' | dc
    }
    
    startTime=$(getCurrentTimeInMili)
    sleep 5
    endTime=$(getCurrentTimeInMili)
    

    If you don’t need this much accuracy, you can simply use the time builtin, as in:

    time sleep 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read a string from a file with shell script variables, and want to
I have a shell script which I want to run without using the sh
hi i want to read the below file using php. the file is of
I have a text file. I want read that file. But In that if
I'm programming Java in Eclipse IDE. Here is code I want to read file:
I have one binary file and I want to read this file like first
I have semicolon-separated .dat file and I want to read that file and store
I have a .txt file having some text. I want to read this file
I have a CSV file that I want to read with Ruby and create
I want to read .json file using jquery. It should read the .json file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.