How to loop bash
command until output no longer contains a string and then print the time the loop was stopped to output? watch
command isn't available.
Bash – Loop bash command until output no longer contains a string
bash
bash
How to loop bash
command until output no longer contains a string and then print the time the loop was stopped to output? watch
command isn't available.
Best Answer
Here's an example of running
date +%S
, which prints seconds part of the current time, every half a second and stops on a condition (see below):The condition stop:
If you uncomment this line only:
it will loop while
5
exists in the output (e.g. while from50
till00
)If you uncomment this line only:
it will loop until
7
exists in the output (i.e. until current seconds = 07, 17, 27, 37, 47 or 57)Sample output for not containing string (
5
in this case):Sample output for containing string (
7
in this case):