I would like to run a command line program again and again inside an infinite loop.
The program will occasionally output different data.
Whenever the new data is output, I would like the previous data to be overwritten.
Example:
The following program will output the time of day.
#include <stdio.h>
#include <time.h>
int main (){
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
}
The naive approach would be the following:
while true; do ./main; clear; done
Of course, this will clear the screen every run, and cause a flicker.
I could certainly pipe it into a custom program that only refreshes output on change,
but I was hoping to find a solution using standard linux commands
(or Bash language features).
The program output could be multi-line, so returning(/r) and re-writting is not an option.