Bash printf control characters

Johnny Rosenberg gurus.knugum at gmail.com
Sat May 24 21:08:20 UTC 2014


2014-05-24 21:17 GMT+02:00 Colin Watson <cjwatson at ubuntu.com>:

> 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]


Thanks! I didn't know about tput and terminfo. I find this very useful!


Johnny Rosenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20140524/715a7c04/attachment.html>


More information about the ubuntu-users mailing list