Bash printf control characters

Colin Watson cjwatson at ubuntu.com
Sat May 24 19:17:24 UTC 2014


On Sat, May 24, 2014 at 07:14:19PM +0200, Johnny Rosenberg wrote:
> Since ”fredag” (friday) is one character shorter than ”torsdag” (thursday),
> the last character of the torsdag line will still remain, won't it?
> So I need something at the end of the string that works like Ctrl+k in the
> terminal (erase everything on the right side of the cursor), but how do I
> implement it?

The terminal sequence required to implement clear-to-end-of-line depends
on the terminal type, so printf can't do it.  However, tput(1) can issue
the correct sequences based on the current terminal type, and
terminfo(5) documents the capability names you need for any given
terminal feature.  In this case, the answer would be:

        printf '\r%(%F %T (%A))T' -1
        tput el

Cheers,

-- 
Colin Watson                                       [cjwatson at ubuntu.com]




More information about the ubuntu-users mailing list