【问题标题】:How to write array elements to a file one per each line in shell? [duplicate]如何在 shell 中每行将数组元素写入一个文件? [复制]
【发布时间】:2023-01-18 22:17:47
【问题描述】:

我在 arr 中有一个数组,其中包含字符串列表 - (string1 string2 string3 ...)

如何将这些元素每行一个元素附加到文本文件中。

元素可以是任何数据类型。但是我需要每行写一个元素,例如:

string1
string2
string3
.
.
.

【问题讨论】:

    标签: linux bash shell terminal bash-completion


    【解决方案1】:

    像这样:

    printf '%s
    ' "${array[@]}" > new_file
    

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2015-03-07
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      相关资源
      最近更新 更多