bash – How to add a progress bar to a shell script? – Stack Overflow
Posted by jpluimers on 2020/03/17
From [WayBack] bash – How to add a progress bar to a shell script? – Stack Overflow (thanks Mitch Haile!):
You can implement this by overwriting a line. Use
\r
to go back to the beginning of the line without writing\n
to the terminal.Write
\n
when you’re done to advance the line.Use
echo -ne
to:
- not print
\n
and- to recognize escape sequences like
\r
.Here’s a demo:
echo -ne '##### (33%)\r' sleep 1 echo -ne '############# (66%)\r' sleep 1 echo -ne '####################### (100%)\r' echo -ne '\n'
–jeroen
Leave a Reply