Hmm. Kind of confused here. Almost too many issues to mention.
First of all, please use [code][/code] tags, to preserve the formatting of the code. It's hard to follow the script without indenting. I had to copy it to a file and re-format it to figure it out.
Now, from the top
Code:
list=`ls *.png` #not so good
1.
$(..) is recommended over `..`
2. You shouldn't need to use ls to create a list of files. Bash has it's own globbing ability.
Code:
$file="./$list" #wrong
I'm not sure what you're trying to do here. This just appends ./ to the front of the first entry in the list of files you created earlier. Not to mention that you never, ever use $ when
setting a variable.
Code:
$image_array = $list #wrong!
Is this supposed to be the place where you populate the array? Because this is exactly NOT
how to do that in bash.
Code:
for((j=0;j<=i;j++)) # not ok
(edit: I just noticed that this is wrong too, since $i is not an integer)
Anyway, there's a more convenient way to loop through array elements in bash.
Code:
for j in ${!image_array[@]} ; do #better
${!array[@]} outputs a list of all existing array indexes.
Code:
if [ -e image_array[j] ]; then #wrong
You do however use $ when you need to fetch the
value of a variable (or array element). Also you should generally quote them in order to protect any spaces in the strings from word breaking.
Code:
if [ -e "${image_array[$j]}" ]; then #right
But why do you need to check if the file exists, when you got the filename from ls in the first place?
Code:
perl clusterImage.pl SampleImage.png
Neither of your perl commands has any input from the array list. I suppose that may be because you're just in testing though.
Anyway, assuming I understand your needs, here's a basic framework of what you should be doing. To tell the truth, I don't see any need at all for an array here, so first of all, here's just a simple loop.
Code:
for i in ./*.png; do
echo "$i"
perl clusterImage.pl "$i" #$i is the input file
perl seperateObjects.pl "$i.kmeansOutput.all.matrix" # the input is $i with the string attached
done
This is assuming that the first script modifies the output filename itself and places it in the working directory.
But if for some reason you really need to use an array, then you just make a simple modification to populate and loop through the array. Probably something like this:
Code:
image_array=( *.png )
for i in ${image_array[@]}; do
echo "$i"
perl clusterImage.pl "$i" #$i is the input file
perl seperateObjects.pl "$i.kmeansOutput.all.matrix" # the input is $i with the string attached
done
...although details like the exact filename format and the perl command input might be important.