[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to read N bytes instead of N characters?
From: |
Lawrence Velázquez |
Subject: |
Re: How to read N bytes instead of N characters? |
Date: |
Mon, 13 May 2024 22:46:23 -0400 |
User-agent: |
Cyrus-JMAP/3.11.0-alpha0-455-g0aad06e44-fm-20240509.001-g0aad06e4 |
On Mon, May 13, 2024, at 5:01 PM, Koichi Murase wrote:
> 2024年5月14日(火) 5:42 Peng Yu <pengyu.ut@gmail.com>:
>> Which variable is the most appropriate to treat bytes as characters?
>> (So that it doesn't have the least side effects irrelevant to my
>> current goal.) Thanks.
>
> The locale category affecting the character counting is LC_CTYPE.
> However, if you set LC_CTYPE globally, it still affects the processing
> of other parts because it is the general setting for the character
> encoding. It is safer to set the locale only for `read' such as «
> LC_ALL=C read -N 4 ... ». Also, if you use LC_CTYPE instead of LC_ALL,
> you need to ensure empty LC_ALL.
See also "Overriding locale categories" here:
https://www.etalabs.net/sh_tricks.html
--
vq