How to print on the same line in shell

#!/bin/bash
for i in `seq 10 1`;do
    echo -en "\r\x1B[2K";
    echo -n "$i";
    sleep 2;
done;

\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.

Time limit is exhausted. Please reload CAPTCHA.

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