readarray 是否允许指定行分隔符?

Tim*_*Tim 3 bash array

在 bashread内置命令中-d,我们必须指定换行符以外的行分隔符

是否readarray提供了一些指定行分隔符的方法?

  • 它没有为此目的的选择是否正确?
  • 是否有用于此目的的外壳默认变量,类似于IFS字段分隔符?

谢谢。


看到steeldriver的评论后,

$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ help readarray
readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
    Read lines from a file into an array variable.

    A synonym for `mapfile'.
Run Code Online (Sandbox Code Playgroud)

但后来我发现:

$ help mapfile
mapfile: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
    Read lines from the standard input into an indexed array variable.

    Read lines from the standard input into the indexed array variable ARRAY, or
    from file descriptor FD if the -u option is supplied.  The variable MAPFILE
    is the default ARRAY.

    Options:
      -d delim  Use DELIM to terminate lines, instead of newline
...
Run Code Online (Sandbox Code Playgroud)

ste*_*ver 8

从 bash 4.4 版开始,是的。从发布公告Bash-4.4 Release Available

最显着的新特性是 mapfile 能够使用任意记录分隔符;

readarray作为 的同义词mapfile)。中的描述man bash

          -d     The first character of delim is used  to  terminate  each
                 input line, rather than newline.
Run Code Online (Sandbox Code Playgroud)

  • @Tim 没有提到“分隔符”。分隔符(换行符,或用 `-d` 指定的字符)在数据中_included_,除非还使用了 `-t`。另请参见 [何时使用术语“分隔符”、“终止符”和“分隔符”](//stackoverflow.com/q/9118769) (2认同)