PDA

View Full Version : [all variants] moving a directory listing into an array



Yulquen
May 19th, 2008, 07:34 AM
hi,

do anyone of you know of a smarter way to do this?

this works:
ls -l -R -a | grep './' | tr -d ':' >~/bin/buffer

num=$(cat ~/bin/buffer|wc -l)

until [ $num = 0 ]; do
array[$num]=$(sed -n -e "$num"p ~/bin/buffer)
num=$(expr $num - 1)
done

but the loop is very slow.
the ls pipe completes in a second, but the loop uses about 35 seconds to complete when buffer is 3200 lines.

is it possible to to it faster? I need this to speed up a
larger script.

thanks in advance for any answers.