This does not appear to be working. When I ran it as in the post above, I simply got no input. I inserted a second "if" loop to see if, in fact, the lines were being read. They are not. With the current version of the script, seen below, the output is:
>
No length
No length
>
This seems odd, because there are currently 39 directories, and the output of the first command, when run on its own, has 41 lines (the 39 directories plus lines for "./" and "../" Any ideas as to what could be causing this? Thanks again.
A bit of a change from the original intent, right now I am just trying to get an array of the first number in the directory, and I had the format slightly wrong. The directories are actually: images_#1_#2_Date/. I figure if I can get the first number working, getting the second into the array should be trivial.
Quote:
#! /bin/ksh
cd images
cnt=0
ls -f1 | sed -e 's/_/ /g' -e 's/_/ /g'| awk '{print $2}'| sort | while read line
do
if [[ ! -z "$line" ]]
then
myarray[$cnt]="$line"
cnt=$(($cnt+1))
fi
if [[ -z "$line" ]]
then
echo "No length"
fi
done
ncnt=0
while [ $ncnt -lt $cnt ]
do
echo "My Array: ${myarray[$ncnt]}"
ncnt=$(($ncnt+1))
done
Sorry, the indentation does not seem to be working.