Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a running clock in terminal using bash without using loop

Tags:

linux

bash

How to display a running clock in a linux terminal without using any for or while loop. Using these loops in scripts with 1 sec duration causes a significant load in the systems.

like image 598
Vijay47 Avatar asked Apr 19 '26 04:04

Vijay47


2 Answers

How about:

watch -n 1 date

Use watch to run a command periodically.

like image 75
Raman Sailopal Avatar answered Apr 21 '26 17:04

Raman Sailopal


This post is ancient, but for anyone still looking for this kind of thing:

#!/bin/bash

printf '\033[;H'
while true; do date; sleep 1; done

This version avoids recursion (and stack faults!) while accomplishing the goal.

(For the record - I do prefer the watch version, but since the OP did not like that solution, I offered an improvement on the other solution.)

like image 31
nclark Avatar answered Apr 21 '26 18:04

nclark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!