help-bash
[Top][All Lists]
Advanced

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

Re: Does mapfile support a multibyte character for its delimiter option?


From: Robin A. Meade
Subject: Re: Does mapfile support a multibyte character for its delimiter option?
Date: Wed, 7 Jul 2021 09:41:39 -1000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

OK, thanks Lawrence, Greg, and Chet.

My current workaround is to assume UTF-8 and use a perl one-liner to preprocess the input, converting the multibyte delimiter character to NUL:

$ mapfile -d '' -t a < <(echo -n 1¥2¥3¥ | perl -Mutf8 -C -l0 -pe 'BEGIN{$/="¥"}')


or more concisely:

$ mapfile -d '' -t a < <(echo -n 1¥2¥3¥ | perl -C -0x00A5 -l0 -pe '')


Then I get my desired result:

$ declare -p a
declare -a a=([0]="1" [1]="2" [2]="3")


(The perl one-liner will need adjustments if using an encoding other than UTF-8.)

This approach will work as long as I stick to an encoding that has the property that a \x00 byte is guaranteed to correspond to U+0000, such as UTF-8.



reply via email to

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