Unexpected End Of File Error

Hi guys,

I am new to BASH scripting and I was wondering if anyone could have a look at this code and explain to me why I am getting an Unexpected End of File Error ?

If you can that would be great / much appreciated! THANKS!

#!/bin/bash
USER=""
PASS=""
if [ -z "$PASS" ]; then echo "You need to set your username and password in the script."; exit 1; fi
wget -q -O .login.html http://www.hackthissite.org/user/login  --post-data="username=$USER&password=$PASS&btn_submit=Login"  --save-cookies=.cookies.txt --keep-session-cookies --referer  http://www.hackthissite.org/
grep "Image Validation" .login.html >/dev/null && echo  "Error: You need to log out/in in a web browser" && exit 1
wget -q -O -  http://www.hackthissite.org/missions/prog/11/   --load-cookies=.cookies.txt --keep-session-cookies --referer  http://www.hackthissite.org/missions/programming/ > out.txt

TEXT=`cat out.txt | grep "Generated String:" | cut -f 2 -d : | cut -f 1 -d "<" | tr -d [:blank:]`
SHIFT=`cat out.txt | grep "Generated String:" | cut -f 3 -d : | cut -f 1 -d "<" | tr -d [:blank:]`

echo "If this doesn't work, you'll need to add this separator:"
echo $TEXT

for EACH in `echo $TEXT | tr "," "\n" | tr ")" "\n" | tr "#" "\n"| tr  "'" "\n"| tr "." "\n"| tr "&" "\n"| tr "(" "\n"| tr "!" "\n"| tr "%"  "\n"| tr "$" "\n"| tr "+" "\n"| tr "-" "\n"| tr "/" "\n"| tr "*" "\n"|  tr "@" "\n"| tr "^" "\n"| tr "\"" "\n"`
do 
let EACH=$EACH-$SHIFT
STRING="$STRING$(printf "\\$(printf "%03o" $EACH)")"
done
echo The string is $STRING
wget -q -O -  http://www.hackthissite.org/missions/prog/11/index.php  --post-data="solution=$STRING"  --load-cookies=.cookies.txt  --keep-session-cookies --referer  http://www.hackthissite.org/missions/prog/11/ > out2.txt
grep "answer is wrong" out2.txt | html2text
grep -i "successfully" out2.txt | html2text
grep -i "already completed" out2.txt | html2text

rm .login.html; rm .cookies.txt; rm out.txt; rm out2.txt

There are is no line containing << so I think that we are looking for a corrupt script.
Please re-post the script after examining it with this sed command which makes control codes visible:

sed -n l scriptname

A normal unix/Linux line terminator will show as a dollar sign.

Please post what Operating System and version you are running.

Ps: I can't follow the logic or reasoning behind the code, but I don't like the look of this line:

for EACH in `echo $TEXT | tr "," "\n" | tr ")" "\n" | tr "#" "\n"| tr  "'" "\n"| tr "." "\n"| tr "&" "\n"| tr "(" "\n"| tr "!" "\n"| tr "%"  "\n"| tr "$" "\n"| tr "+" "\n"| tr "-" "\n"| tr "/" "\n"| tr "*" "\n"|  tr "@" "\n"| tr "^" "\n"| tr "\"" "\n"`

Ignoring quote a lot of the code, why no double quotes round $TEXT if it can contain Shell Special Characters? Try putting double-quotes round every string variable in this script. What in words is the line intended to do? The tr commands can be condensed into a single tr command enclosed in single quotes (to stop the Shell reacting to Shell Special Characters).
Something like (untested):

for EACH in `echo "${TEXT}"|tr ',)#".&(!%$+-/*@^\' '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'`

Ps. In my experience it is better to test for the valid characters than to try to eliminate the invalid characters.