On Fri, Apr 05, 2019 at 03:57:16PM -0700, L A Walsh wrote: > What would be wrong with doing something like: > > readarray -t last10< <(COMMAND |tail -10) > > That will put the last 10 lines of COMMAND_OUTPUT into > the array 'last10'. Now you can launch another command > to process that last 10 lines. Note that I used the '-t' > which strips off the '\n' at the end of line. For about > 50% of the uses, you might want to keep the line ending > (and not use the '-t' option). Example. Using 'seq' > to generate lines of output, if I use -t, I might get: > > > readarray -t last10< <(seq 1 100|tail -10) > > printf "%s" "${last10[@]}" > 919293949596979899100> > > Which may not be what you want. But you could keep the > newline when reading it in and it will be used on output: > > > readarray last10< <(seq 1 100|tail -10) > > printf "%s" "${last10[@]}" > 91 > 92 > 93 > 94 > 95 > 96 > 97 > 98 > 99 > 100
That would be an extremely uncomfortable way to use an array of numbers for any purpose other than printing them to stdout. You virtually always want to use readarray -t, to store the numbers without their trailing newlines. That lets you use them as numbers in math contexts, or print them as part of a line of text, etc. If you want to print them one-per-line, you can simply do: printf '%s\n' "${array[@]}"