You're viewing a comment by Peteches and its responses.

Peteches Permalink
June 12, 2012, 16:32

nice work, I Love bash scripting, looking forward to the rest of this series!

For number 4 though you say that the while read line format is the only way to read in a file line by line, however bash 4.x mapfile allows you to read in a file to an indexed array more efficiently, you can then run the for loop over the array. eg

mapfile ARRAY < file

There are also a number of options which allow you to control input
-s count - skip the first count lines
-n count - read in at most count lines
-c quanta - set a quanta for the -C option
-C command - run command every quanta lines passing the index of the array about to be assigned
-0 index - start assigning at array[index] instead of 0
-t - strip trailing newline
-u fd - read from file descriptor fd instead of stdin

excellent alternative to the while read loop in my opinion


Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "computer_325": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.