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

  • SEARCH
  • Home
  • 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 7831045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:32:54+00:00 2026-06-02T11:32:54+00:00

You can think of this like a really simple stopwatch. I’m trying to hack

  • 0

You can think of this like a really simple stopwatch. I’m trying to hack together a bash script that displays the elapsed time since a specified date and updates the output every second.

First, Inside the script you’d specify a UNIX date: Fri Apr 14 14:00:00 EDT 2011. This would be when the stopwatch starts.

Now, when you run the script, you’d see…

06d:10h:37m:01s

and a few seconds later you’d see…

06d:10h:37m:05s

I’m not trying to have a new line printed for every second that elapses. The script should only have 1 line of output, and update it every second. Obviously you could quit the script and start it up again at any time, and it would still be right on since the starting time is hard coded.

Any ideas?

  • 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-02T11:33:00+00:00Added an answer on June 2, 2026 at 11:33 am

    I use the following code snippet in long-running scripts.
    The timer runs in a function (separate process) which will be killed (trap) if the main process is terminated by a keybord interrupt. The output shows the time elapsed from the start of the timer:

    ... working [hh:mm:ss]  00:07:58
    

    The snippet:

    #===  FUNCTION  ================================================================
    #          NAME:  progressIndicatorTime
    #   DESCRIPTION:  Display a progress indicator with seconds passed.
    #    PARAMETERS:  [increment]   between 1 and 60 [sec], default is 2 [sec]
    #===============================================================================
    function progressIndicatorTime ()
    {
      declare default=2                                       # default increment [sec]
      declare increment="${1:-$default}"                      # 1. parameter or default
      declare format='\b\b\b\b\b\b\b\b%02d:%02d:%02d'         # time format hh:mm:ss
      declare timepassed=0
      declare seconds minutes hours
    
      [[ ! "$increment" =~ ^([1-9]|[1-5][0-9]|60)$ ]] && increment=$default
      printf " ... working [hh:mm:ss]  00:00:00"
      while : ; do                                            # infinite loop 
        ((seconds=timepassed%60))
        ((minutes=timepassed/60))
        ((hours=minutes/60))
        ((minutes=minutes%60))
        printf "$format" $hours $minutes $seconds
        sleep $increment || break                             # sleep ...
        ((timepassed+=increment))
      done
    }    # ----------  end of function progressIndicatorTime  ----------
    
    progressIndicatorTime &                                   # run progress indicator
    declare progressIndicatorPid=${!}                         # save process ID
    trap  "kill $progressIndicatorPid" INT TERM               # trap keyboard interrupt
    
    #
    # run long command
    #
    
    kill -s SIGTERM $progressIndicatorPid                     # terminate progress indicator
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think that some newer languages like JS can do this natively, but I
This seems like a really, really simple problem, but I can't figure it out.
I think that my issue should be really simple, yet I can not find
I think this is really simple, but I can't get my head around it.
I feel like this is a stupid question, but I can't think of a
i think this is a simple question but I've searched around and can't seem
I think this is a simple question, but I can not find the answer
I feel like the answer to this question is really simple, but I really
I want to do something really simple like this: JPanel htmlPanel = new HtmlPanel(<html><body><h1>hello
how can i create menu like this.??? Thank you.

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.