Thats the issue with the emulators. Dont get confused, emulators are not real shells, they are made to mimic some of the qualities of shells ! If you try that on a Bash/sh/ksh/csh it will works fine.
-Peace
Unix 101:
1)The 1st line you are placing in a shell script is which shell you want to run the command in.
2)if you trying to run a script as "sh script" you are saying run the set of commands in script in sh(bourne shell). And any line starting with # is a comment and so the 1st line has no significance.
3)If you want to run your script your way try "bash script" and it will work fine. Else change the mode on the file to have execute bit (chmod +x script)and you could run the script as ./script from the dir where it is located.