[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
%lc/%ls print nothing in C locale if argument has bytes >7f
From: |
Emanuele Torre |
Subject: |
%lc/%ls print nothing in C locale if argument has bytes >7f |
Date: |
Fri, 8 Mar 2024 16:56:25 +0100 |
User-agent: |
Mutt/2.2.12 (2023-09-09) |
Hello.
I have noticed that, in C locale, %lc prints nothing if the first byte
of the argument is non-ASCII (0x80-0xff).
This is the only way %...c can ever output 0 bytes in bash, so it is
probably unintenional.
$ LC_ALL=C; { printf %lc%n è x; declare -p x >&2;} | od -An -to1
declare -- x="0"
$ LC_ALL=C; { printf %lc%n $'\x80' x; declare -p x >&2;} | od -An -to1
declare -- x="0"
$ LC_ALL=C; { printf %lc%n 1$'\x80' x; declare -p x >&2;} | od -An -to1
declare -- x="1"
061
I would expect %lc in C locale to work like %c, so print the first byte
of the argument; that is ksh93's %Lc does.
$ LC_ALL=C; { printf %Lc%n è x; typeset -p x >&2;} | od -An -to1
typeset -i x=1
303
%.1ls has a similar problem.
It appears that it will print nothing if there is a non-ASCII byte
anywhere in the string when using %ls, or anywhere in first N bytes when
using %.Nls.
$ LC_ALL=C; { printf %ls%n 1fooèax x; declare -p x >&2;} | od -An -to1
declare -- x="0"
$ LC_ALL=C; { printf %.3ls%n 1fooèax x; declare -p x >&2;} | od -An -to1
declare -- x="3"
061 146 157
$ LC_ALL=C; { printf %.7ls%n 1fooèax x; declare -p x >&2;} | od -An -to1
declare -- x="0"
I would also expect %ls to work like %s in C locale; again, that is what
ksh93's %Ls does.
o/
emanuele6
- %lc/%ls print nothing in C locale if argument has bytes >7f,
Emanuele Torre <=