Creating an array from a text file in Bash

前端 未结 6 1818
小鲜肉
小鲜肉 2020-11-22 10:25

A script takes a URL, parses it for the required fields, and redirects its output to be saved in a file, file.txt. The output is saved on a new line each time a fie

6条回答
  •  花落未央
    2020-11-22 11:04

    Use the mapfile command:

    mapfile -t myArray < file.txt
    

    The error is using for -- the idiomatic way to loop over lines of a file is:

    while IFS= read -r line; do echo ">>$line<<"; done < file.txt
    

    See BashFAQ/005 for more details.

提交回复
热议问题