Whats is now in your test.sh script?
I hit that problem until I put the "#!/bin/bash" line at the start. If that is missing or wrong then you will get that error.
Note that the second line appends to the test.sh file instead of overwriting it.
Cheers,
Simon