help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to read N bytes instead of N characters?


From: Peng Yu
Subject: Re: How to read N bytes instead of N characters?
Date: Mon, 13 May 2024 15:42:02 -0500

I see that LC_ALL and LANG can affect the length calculation. Are
there other locale variables that can affect the length calculation?
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.

$ x=σ
$ export LC_ALL=C
$ echo ${#x}
2
$ unset LC_ALL
$ echo ${#x}
1
$ export LANG=C
$ echo "${#x}"
2
$ LANG='en_US.UTF-8'
$ echo "${#x}"
1

On Mon, May 13, 2024 at 2:27 PM Chet Ramey <chet.ramey@case.edu> wrote:
>
> On 5/13/24 1:34 PM, Peng Yu wrote:
>
> > Is there a way to read N bytes instead of N chars in bash? Thanks.
>
> Set your locale to something like C or POSIX that doesn't do multibyte
> character encoding.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>


-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]