logo
  • 教程列表
  • SO官方文档
  • 数组
    • 数组分配
    • 访问数组元素
    • 数组修改
    • 数组长度
    • 数组迭代
    • 关联数组
    • 循环通过一个数组
    • 销毁删除或取消设置数组
    • 初始化索引列表
    • 字符串中的数组
    • 将整个文件读入数组
    • 数组插入功能
  1. StackOverflow 文档
  2. Bash 教程
  3. 数组
  4. 将整个文件读入数组

将整个文件读入数组

Created: November-22, 2018

阅读一步:

IFS=$'\n' read -r -a arr < file

循环阅读:

arr=()
while IFS= read -r line; do
  arr+=("$line")
done

Version >= 4.0

使用 mapfile 或 readarray(它们是同义词):

mapfile -t arr < file
readarray -t arr < file
  • 数组插入功能
  • 字符串中的数组

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明