|
An array is a table of values.
array[0]=fred
array[1]=barney
puts two values in the array. I can see the first one with:
echo ${array[0]}
That [0] is called the subscript. Instead of a constant, it can be a variable.
echo ${array[i]}
will do different things depending on the value of i.
echo ${array[@]}
will echo all values (fred and barney in this case) in the array.
echo ${#array[@]}
will echo 2 since there are two elements in the array.
while (i<${#array[*]}))
in this case would loop until i is greater than or equal to two. Since i starts at zero, the loop will run twice with i at 0 and 1. Which is just right to examine each element of the array.
"found" is a flag, not a count. At first it is zero since we have not found what we are looking for. If we find it, found becomes one.
|