0

sleep command can be used to introduce a delay. e.g. sleep 5 will sleep for 5 seconds.

Is there any alternative/way/method that will display the pending seconds on the terminal?

output like

 resuming in 5 sec

the numeric values just countdowns on the same line of terminal.

2

A hacky approach using pv:

$ yes | pv -SeL1 -s 5 > /dev/null
ETA 0:00:04

Or:

$ yes | pv -SL1 -F 'Resuming in %e' -s 5 > /dev/null
Resuming in ETA 0:00:04

pv is normally used to give a progress bar for the I/O of some data stream. Here we're using the constant stream of the yes command, but rate-limiting it to 1 byte per second (-L1), and Stopping after the output has reached a size of 5 bytes.

You can add more in there like the elapsed time, ETA as in clock time when it's expected to finish, or even a progress bar:

$ yes | pv -SpeL1 -s 5 > /dev/null
[===========>                                                  ] 20% ETA 0:00:04

Note that the duration won't be exactly 5 seconds (closer to 6 actually here with pv 1.6.6 in my tests).

Speaking of progress bar, you can also feed its output to zenity (graphical) or diaglog/whiptail for an even fancier display:

yes | pv -SnL1 -s 5 2>&1 > /dev/null | 
  zenity --progress --auto-close --no-cancel \
         --title 'Please wait...' --text 'Please wait...'

zenity

yes | pv -SnL1 -s 5 2>&1 > /dev/null |
  whiptail --gauge 'Please wait...' 5 20 0

whiptail

For a smoother progress, you can increase the rate to 10 bytes per second (and multiply the cut-off size by 10) while telling it to give you 10 updates per second:

yes | pv -SpeL10 -i0.1 -s 50 > /dev/null
yes | pv -SnL10 -i 0.1 -s 50 2>&1 > /dev/null |
  whiptail --gauge 'Please wait...' 6 20 0
| improve this answer | |
1

Running sleep 5 times?

for ((i=5;i>0;i--)); do printf '%s %s\r' "$i" 'seconds pending'; sleep 1; done; echo

The precision is quite good, there's just the overhead of the loop.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.