首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >readarray允许指定行分隔符吗?

问readarray允许指定行分隔符吗?
EN

Unix & Linux用户
提问于 2018-11-17 16:15:42
回答 1查看 9.6K关注 0票数 3

在bash中,read内置有-d,用于指定换行符以外的行分隔符。

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

  • 为此目的,它没有选择是正确的吗?
  • 有类似于字段分隔符的shell默认变量吗?

谢谢。

在我看到steeldriver的评论后,

代码语言:javascript
复制
$ 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'.

但后来我发现:

代码语言:javascript
复制
$ 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
...
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-11-17 16:43:52

从bash版本4.4开始,是的。发布公告中的可用Bash-4.4版本:

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

(readarray是mapfile的同义词)。man bash中的描述是

代码语言:javascript
复制
          -d     The first character of delim is used  to  terminate  each
                 input line, rather than newline.
票数 11
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/482358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档