user1424739
user1424739

Reputation: 13785

How to clear a line on Mac OS Terminal?

http://ascii-table.com/ansi-escape-sequences-vt-100.php

The above table shows that Esc[2K clears a line.

But on Mac Terminal, I don't see the line is cleard.

$ echo abc$'\e[2k'
abc

The TERM variable is the following.

$ declare -p TERM
declare -x TERM="xterm-256color"

Does anybody how to clear a line? (If possible, it should work on other terminals as well other than Mac Terminal.) Thanks.

Upvotes: 2

Views: 1168

Answers (1)

Inian
Inian

Reputation: 85895

I would just wager it as minor typo, because the escape sequence associated with clearing a line is Esc[2K with an upper case K and not k

echo -e abc$'\e[2K'

should work just as expected. Note that echo -e and the ANSI C style escapes ($'...') are bash shell specific and non POSIX conformant. You can always use printf() that supports escape sequences too

printf abc'\e[2K'

Also the escape character notation \e may not be supported in all versions of echo, but the only the bash built-in provided. You could use the hex equivalent of \e as \x1B or an octal equivalent of \033.

Upvotes: 2

Related Questions