Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 09-23-2004
douknownam douknownam is offline
Registered User
 

Join Date: May 2004
Posts: 35
Lightbulb

i guess i don't know what it is. my thought of an array was a way to use multiple values for one variable name. well, I wanted to use your code of reading 2 files (lists) and using the variables on a conditional basis to print a message. (won't go any further, due to cross-posting).

ok, so in this part:


Code:
i=0
exec < file1
while read array[i] ; do
      ((i=i+1))

done

you're reading the file in and looping.

My confusion is with this part:

Code:
exec <file2
while read entry ; do
      i=0
      found=0
      while ((i<${#array[@]})) ; do
            if [[ $entry = ${array[i]} ]] ; then
                 found=1
                 break
                 ((i=i+1))
            fi
      done
      if ((found)) ; then
            echo $entry is in file1
      else
            echo $entry is not in file1
      fi
done

I assume that the found=0 is setting the count to zero? This line is the most confusing to me: while ((i<${#array[@]})) ; do

Are you saying do .. while "i" is less than the value of array[@]?
Thanks for any input.