Displaying Array Elements in Shell Scripts

Hi All,

I am using the following piece of script to print all the array elements in a script by name compare.sh:

31 len=${#array
[*]};
32 j=0;
33 #echo "The length of the array is : $len"
34 while [$j -lt $len]; do
35 temp=${array[$j]}
36 echo "$temp"
37 let $j++
38 done

But I am getting the following error.

ksh: ./compare.sh[38]: [0: not found

I couldn't understand what is happening...

Can anyone help me on this.....

Thanks in advance

Anand.

You need a space after the [ in the while -- [ is the name of a command (!) and needs to be written with a space after it, just like any other command.

Hi era ,

thanks for your help!!!!

It works fine after your suggestion....

Thanks a lot....

Anand.