Reputation: 31
In general, we see programs running and showing from how long it running in realtime
example
[#] Scanning is running from 1min 30sec
The value will keep change dynamically untill the script complete.
How can we do it in bash !
Upvotes: 1
Views: 102
Reputation: 247012
By using printf with a carriage return but no newline
count=0
SECONDS=0
while ((count < 10)); do
# computation code goes here
# just use a sleep for demonstration
sleep 1
printf "\rRunning for %d seconds" $SECONDS
((count++))
done
echo # just to add a newline in the output
SECONDS is a special variable in bash
Upvotes: 1