在bash中,read内置有-d,用于指定换行符以外的行分隔符。
readarray提供了一些指定行分隔符的方法吗?
谢谢。
在我看到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
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'.但后来我发现:
$ 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
...发布于 2018-11-17 16:43:52
从bash版本4.4开始,是的。发布公告中的可用Bash-4.4版本:
最显著的新特性是mapfile使用任意记录分隔符的能力;
(readarray是mapfile的同义词)。man bash中的描述是
-d The first character of delim is used to terminate each
input line, rather than newline.https://unix.stackexchange.com/questions/482358
复制相似问题