printf(1) and UTF-8 multi-byte chars
    Matthias Apitz 
    guru at unixarea.de
       
    Sat Oct 17 19:18:55 UTC 2020
    
    
  
If you look at the two examples:
$ printf "[%-10s]\n" "xxxx?xxx"
[xxxx?xxx  ]
$ printf "[%-10s]\n" "xxxx¿xxx"
[xxxx¿xxx ]
you see that in the first two blanks are used to fill the '%-10s'
pattern, while in the second only one blank is used. For sure, the
problem/bug has todo with being '¿' a multi-byte UTF-8 char:
$ echo '¿' | od -tx1
0000000    c2  bf  0a
i.e. with "xxxx¿xxx" 8 chars plus one blank are printed to give %-10s, with 
"xxxx?xxx" 8 chars plus two blanks are printed. This means the output of
printf(1) is byte oriented and not character oriented.
Is there a way to print it like this:
[xxxx¿xxx  ]
[xxxx?xxx  ]
Thanks
	matthias
-- 
Matthias Apitz, ✉ guru at unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
Без книги нет знания, без знания нет коммунизма (Влaдимир Ильич Ленин)
Without books no knowledge - without knowledge no communism (Vladimir Ilyich Lenin) 
Sin libros no hay saber - sin saber no hay comunismo. (Vladimir Ilich Lenin)
    
    
More information about the freebsd-questions
mailing list