Problem with Array in Script

Below is my script. This script is getting an error code such as this one.

fileListener.bat: entityArray[1]=craig.uss@pnc.com: not found
craig.uss@pnc.com
fileListener.bat: entityArray[2]=duns_noncusts.txt: not found
duns_noncusts.txt
fileListener.bat: entityArray[3]=duns_misc.cpy: not found
duns_misc.cpy
fileListener.bat: bad substitution
#!/bin/sh
cd /discovery/trigger
set -a entityArray[3]
count=1
while [ true ] 
do
    for f in `ls /discovery/trigger`
    do
   
   if [ $f -eq "*.trg" ]; then
     echo ${f}
     cd /export/home/disadm/BAT
     while read line
     do
         entityArray[$count]=$line
  echo $line
  
  if [ $count -eq 3 ]; then
      break
  fi
  count=`expr $count + 1`
            done < /discovery/trigger/${f}
     cd /export/home/disadm/BAT
     createentity \"${entityArray[1]}\" "Mainframe Flat Files" datafile \"${entityArray[2]}\" schemafile \"${entityArray[3]}\"
     cd /discovery/trigger
     ${f%.trg}
     mv ${f} ${f}.prc
     rm ${f}
    fi
     done    
done

I have no idea what is wrong with this code, or why it won't work. Please help

I think your problem is that you are using /bin/sh as your interpreter:

#!/bin/sh

I believe it does not support arrays, so its not able to parse your assignment statement properly and tries to execute it as a command and thus the error. Try using ksh:

#!/bin/ksh

Thank you for helping me with this. I ran the script changing that to #!/bin/ksh

however, I get the following error
______________________________
$ r 275
filelistener
filelistener[12]: new.trg: bad number
filelistener[12]: new.trg: bad number
filelistener[12]: new.trg: bad number
filelistener[12]: new.trg: bad number

You can not use '-eq' operator to compare strings. It is used with integers only.

change:

if [ $f -eq "*.trg" ]; then

to:

if [[ $f = *.trg ]]; then

If you wanted to use Bash instead of Korn (and on some systems sh is Bash), you'll want to define arrays like this:

declare -a entityArray

And use them like this:

${#entityArray
[*]} #Gets number of elements in array
${entityArray[$x]} #Gets x'th element is array
${entityArray
[*]} #Gets all elements in array

Ben