{"id":5538,"date":"2019-11-26T23:53:05","date_gmt":"2019-11-26T15:53:05","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=5538"},"modified":"2019-11-28T21:49:05","modified_gmt":"2019-11-28T13:49:05","slug":"mapfile","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/mapfile","title":{"rendered":"mapfile\u547d\u4ee4 – \u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u884c\u5e76\u8d4b\u503c\u5230\u6570\u7ec4"},"content":{"rendered":"\n

mapfile\u547d\u4ee4\u7528\u4e8e\u4ece\u6807\u51c6\u8f93\u5165\u6216\u6587\u4ef6\u63cf\u8ff0\u7b26\u8bfb\u53d6\u884c\u5e76\u8d4b\u503c\u5230\u6570\u7ec4<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong> mapfile [\u53c2\u6570] <\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong> <\/p>\n\n\n\n

-n count<\/td>\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u83b7\u53d6\u6700\u591acount\u884c\uff0c\u5982\u679ccount\u4e3a\u96f6\u90a3\u4e48\u83b7\u53d6\u5168\u90e8<\/td><\/tr>
-O origin<\/td>\u4ece\u6570\u7ec4\u4e0b\u6807\u4e3aorigin\u7684\u4f4d\u7f6e\u5f00\u59cb\u8d4b\u503c\uff0c\u9ed8\u8ba4\u7684\u4e0b\u6807\u4e3a0<\/td><\/tr>
-s count<\/td>\u8df3\u8fc7\u5bf9\u524dcount\u884c\u7684\u8bfb\u53d6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong> <\/p>\n\n\n\n

\u5148\u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u7528\u7684\u6587\u4ef6alpha.log\uff0c\u6bcf\u884c\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u517126\u884c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]#  echo {a..z} | tr \" \" \"\\n\" >alpha.log\n[root@linuxcool ~]#  cat alpha.log\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz<\/pre>\n\n\n\n

\u8bfb\u53d6alpha.log\u6587\u4ef6\u5e76\u5c06\u6bcf\u4e00\u884c\u5b58\u50a8\u5230\u6570\u7ec4myarr\u4e2d(\u5982\u679c\u4e0d\u6307\u5b9a\uff0c\u5219\u5b58\u50a8\u5230\u9ed8\u8ba4\u7684MAPFILE\u6570\u7ec4\u4e2d)\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# mapfile myarr <alpha.log\n[root@linuxcool ~]# echo ${myarr[@]}\na 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\n[root@linuxcool ~]#  echo ${myarr[2]}\nc<\/pre>\n\n\n\n

\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u83b7\u53d6\u6700\u591a6\u884c\u6570\u636e\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# mapfile -n 6 myarr <alpha.log \n[root@linuxcool ~]# echo ${myarr[2]}            \nc\n[root@linuxcool ~]# echo ${myarr[@]}             \na b c d e f<\/pre>\n\n\n\n

\u4ece\u6570\u7ec4\u4e0b\u6807\u4e3a6\u7684\u4f4d\u7f6e\u5f00\u59cb\u8d4b\u503c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# mapfile -O 6 myarr <alpha.log \n[root@linuxcool ~]# echo ${myarr[@]}             \ng h i j k l 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<\/pre>\n\n\n\n

\u8df3\u8fc7\u5bf9\u524d6\u884c\u7684\u8bfb\u53d6\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# mapfile -s 6 myarr <alpha.log \n[root@linuxcool ~]# echo ${myarr[@]}             \ng h i j k l m n o p q r s t u v w x y z<\/pre>\n","protected":false},"excerpt":{"rendered":"

mapfile\u547d\u4ee4\u7528\u4e8e\u4ece\u6807\u51c6\u8f93\u5165\u6216\u6587\u4ef6\u63cf\u8ff0\u7b26\u8bfb\u53d6\u884c\u5e76\u8d4b\u503c\u5230\u6570\u7ec4 \u8bed\u6cd5\u683c\u5f0f\uff1a mapfile [\u53c2\u6570] \u5e38\u7528\u53c2\u6570 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/5538"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=5538"}],"version-history":[{"count":9,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/5538\/revisions"}],"predecessor-version":[{"id":5834,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/5538\/revisions\/5834"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=5538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=5538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=5538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}