Read n lines at a time using Bash

前端 未结 15 2805
难免孤独
难免孤独 2020-11-30 00:25

I read the help read page, but still don\'t quite make sense. Don\'t know which option to use.

How can I read N lines at a time using Bash?

15条回答
  •  执念已碎
    2020-11-30 00:51

    Just use a for loop:

    for i in $(seq 1 $N) ; do read line ; lines+=$line$'\n' ; done
    

    In bash version 4, you can also use the mapfile command.

提交回复
热议问题