Assigning values to an array via for/while loop

I need to do something like this:

for i in 1 2 3 4 5; do
       arr[$i]=$(awk 'NR="$i" { print $2 }' file_with_5_records)
done

That is, parse a file and assign values to an array in an ascending order relative to the number of record in the file that is being processed on each loop.

Is my syntax wrong? Is there a trick? I can't seem to get the values assigned properly, does the shell forget them when it exits the loop? Is this even possible?

for i in 1 2 3 4 5; do
      arr[$i]=$(awk 'NR=="$i" { print $2 }' file_with_5_records)
done

Got that far.

So YES: my syntax was incorrect to begin with. I've been dabbling with programming so little that I still have trouble remembering that = is an assignment and not a comparison.

The script still doesn't do what I want because AWK doesn't know the value of $i. I need to pass it to AWK somehow, or come up with a different approach.

Any tips/workarounds...??

I'm really looking forward to getting stuck at some more profound obstacles...

Figured it out.

for i in 1 2 3 4 5; do
        arr[$i]=$(awk 'NR=='"$i"' { print $2 }' examplefile)
        print ${arr[$i]}
done

Testing...

$ cat examplefile
skipme printme1 skipmetoo
skipme printme2 skipmetoo
skipme printme3 skipmetoo
skipme printme4 skipmetoo
skipme printme5 skipmetoo

$ for i in 1 2 3 4 5; do
> arr[$i]=$(awk 'NR=='"$i"' { print $2 }' examplefile)
> print ${arr[$i]}
> done
printme1
printme2
printme3
printme4
printme5

Use the shell variable wrapped in double quotes inside single quotes to pass it to awk.