Shell script doubts

Hello please kindly solve these doubts i have about the following scripts

Script 1
//Shell script that accepts arguments and prints them in reverse order//
echo "number of arguments"
len=$#;
while [ $len -ne 0 ]
do
   eval echo \$$len
   len=`expr $len - 1`
done

---------
Output

$sh test.sh a b
b
a

1.what is \$$len .what is the significance of the escape sequence

Script 2

//Bundle shell script that accepts file name as arguments and create a shell scipr that has the file \
as well as the code to recreate the files.Thus if the script generated by your script is executed \
it would recreate the original file//

echo "#to bundle ,sh this file"
for i in $*
do
   echo "echo $i 1>&2"
   echo "cat > $i <<'end of $i'"
   cat $i
   echo " end of $i"
done


---------------
Output
$cat f1
hi
$cat f2
hello
$sh test.sh f1 f2 >new.sh
$rm f1 f2
$sh new.sh
f1
f2

1.Even though the 1st line is a simple print statement if i write something different I get the following error message :

"new.sh: line 1: to: command not found".

Can u tell me why do i get this message
2.In the 4th line what does 1>&2 mean
3.Is "end of" a command and what does "<<" mean.

please help me with this

Read and learn what is here: (will explain 3, and perhaps 1...)
Here document - Wikipedia, the free encyclopedia

1>&2 : Redirect STDOUT to STDERR (???)

eval echo \$$len

The parameters of a shell script are available as $1, $2...$n
So by escaping the dollar we get a literal "$" followed by the position we wish to display.
eval uating this returns the value of the parameter at that position.