Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: sh emulation POSIX non-conformances (printf %10s and bytes vs character)



2021-04-23 18:53:26 +0200, Vincent Lefevre:
[...]
> Some file formats have fields with a byte-size limit. Providing
> more than this limit could have unexpected effects. One may also
> want to limit the size of generated filenames (see NAME_MAX).
[...]

printf is to print formatted text.

If you want to work at byte level, you need to use the C locale
(or in zsh disable the multibyte option). In zsh, that applies
to printf and all other text utilities and operators which is
more consistent than the POSIX API.

Note that the printf of perl, fish, gawk (and I'd expect most
modern languages) work at character level (possibly as wrappers
for C's wprintf()).

$ perl -CLSA -le 'for (@ARGV) {printf "|%10s|\n", $_}' Stephane Stéphane
|  Stephane|
|  Stéphane|

-- 
Stephane




Messages sorted by: Reverse Date, Date, Thread, Author