readarrayでは、行区切り文字を指定できますか?

readarrayでは、行区切り文字を指定できますか?

bashでは、read組み込みコマンドを使用して-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'.

しかし、私は次のことを知りました。

$ 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
...

ベストアンサー1

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.

おすすめ記事