Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the mapfile command of Linux

Shulou Source: shulou.com Published: 2022-06-01 17:25:15 10月02日 Update

This article mainly explains "how to use Linux mapfile command", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to use Linux mapfile command"!

The mapfile command is used to read lines from standard input or file descriptors and assign them to arrays.

syntax mapfile [parameter]

Common parameters: -n count Get up to count lines from standard input, if count is zero then get all-O origin Start assigning values from the array subscript origin, the default subscript is 0-s count Skip reading the first count line Reference Example First create an example file alpha.log, one lowercase letter per line, 26 lines in total:

[root@linux265 ~]# echo {a.. z} |tr " "\n" >alpha.log [root@linux265 ~]# cat alpha. log a b c d e f g h i j k l m n o p q r s t u v w x y z Read the alpha.log file and store each line in the array myarr (or in the default MAPFILE array if not specified):

[root@linux265 ~]# mapfile myarr Get up to 6 lines of data from standard input: [root@linux265 ~]# mapfile -n 6 myarr Start assigning values from array subscript 6:[root@linux265 ~]# mapfile -O 6 myarr At this point, I believe that everyone has a deeper understanding of "how to use Linux mapfile command", you may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Command array subscript file standard input location content parameter commonly used storage learning practical deeper one line interest letter instance practicality actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Shulou Tech Info Huawei macOS