Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the mapfile command of linux to read rows from standard input and assign them to an array

Shulou Source: shulou.com Published: 2022-06-02 12:44:45 09月21日 Update

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

Tags: Array standard input command file parameter article storage line subscript location letter done instance lowercase commonly used data more format knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Information NVidia Shulou Technology Redmi