在 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)
从 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)