Use the mapfile command of linux to read rows from standard input and assign them to an array
Editor to share with you the use of linux's mapfile command to read rows from standard input and assign values to the array. I hope you will learn a lot after reading this article. Let's discuss it together.
The mapfile command is used to read lines from standard input or file descriptors and assign values to an array
Syntax format: mapfile [parameters]
Common parameters:
Reference example
First create a file alpha.log for the example, one lowercase letter per line, with a total of 26 lines:
[root@linuxcool ~] # echo {a.. z} | tr "\ n" > alpha.log [root@linuxcool ~] # cat alpha.logabcdefghijklmnopqrstuvwxyz
Read the alpha.log file and store each line in the array myarr (if not specified, in the default MAPFILE array):
[root@linuxcool ~] # mapfile myarr