Intro
I'm using the pv
command in a pipe to show a progress bar. I tried it with a simple counter:
for (( i = 1 ; i <= 100 ; i++ )); do sleep 1; echo $i; done | pv --progress --line-mode --size 100 --eta --timer
This works fine, but I'd like the progress bar to show on the same line. This answer explains how to do that.
So I tried this:
for (( i = 1 ; i <= 100 ; i++ )); do sleep 1; echo $i; done | >&2 echo -en "\r"; pv --progress --line-mode --size 100 --eta --timer
It stays on one line, but now it doesn't update the ETA anymore.
Question
How can I get the ETA to update too?
Update
Now that iBug answered the question from the previous section, I realized I had one more requirement that's relevant: the stdout
needs to be preserved so it can be used in the next pipe. In my specific case I need to write the result to a file (i.e. > some-file.txt
)