How to print on the same line in shell

for i in `seq 10 1`;do
    echo -en "\r\x1B[2K";
    echo -n "$i";
    sleep 2;

\x1b[2K is what’s known as an ANSI terminal control sequence.

\x1b is the ASCII for ESCAPE (literally the ESC key on your keyboard). [2K is the command “erase the current line”.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.