Your chunk function can be implemented in bash as follows.
chunk(){ size=$1 n=$2 firstline=$((n*size)) i=0 while [ $i -lt $firstline ] do read -r junk || return i=$((i+1)) done i=0 while [ $i -lt $size ] do read -r str || return printf "%s\n" "$str" i=$((i+1)) done }
Note that results may be unexpected if files are added in between calls to find. So, you may want to implement a save_chunks/get_chunk API instead of your requested one, or do something like:
catn(){ i=0 while [ $i -lt $1 ] && read -r s do printf "%s\n" "$s";i=$((i+1)) done } find -f . | (catn 10; # shows first chunk of size 10 catn 10; # second chunk of size 10 catn 10; # last of size < n catn 10) # does nothing
This should also be faster.