help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Readig multiple null-separated values


From: Koichi Murase
Subject: Re: [Help-bash] Readig multiple null-separated values
Date: Mon, 29 Jul 2019 21:50:21 +0900

> My question is:
>
> 1) Is there a simpler solution than my read_nullbyte() function?
>
> 2) Do you consider it generic and useful enough to make it built-in part
> of GNU Bash?
>
> Franta

In Bash 4.4, the builtin `mapfile' has an opton `-d delim' which
enables to change the delimiter from newlines. It accepts an empty
string which actually behaves as NUL separator. For example, the
provided example can be written with `mapfile' as follows:

  $ printf 'a\0aaa\0b\0bbb\0c\0ccc' | { mapfile -d '' arr; declare -p arr; }
  declare -a arr=([0]="a" [1]="aaa" [2]="b" [3]="bbb" [4]="c" [5]="ccc")

On Mon, 29 Jul 2019 at 21:06 David <address@hidden>:
>
> On Sat, 27 Jul 2019 at 23:56, František Kučera <address@hidden> wrote:
> >
> > in my Bash pipelines I sometimes pass data separated by null byte \0 and
> > (strip)
> > data between processes.
>
> When you use the word "data" above, do you mean ASCII text,
> or something else?
>
> If ASCII text, are you aware of the ASCII delimiter characters?
> See https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
>

Actually I also wanted similar functionality sometimes. For example,
the functionality of Bash that can handle NUL separated data should be
useful for treating filenames because the only character that cannot
appear in any filepath is NUL. Those control characters (FS/GS/RS/US)
can appear in filenames (at least in Linux filesystems), so when the
processed filenames are not under my control (for example when I
provide some scripts to other users), I want to avoid using
FS/GS/RS/US as separators even if such filenames with control
characters are unlikely.

--
Koichi



reply via email to

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