I've sometimes gotten some extremely cryptic error messages that turned out to be due to invisible characters in the text of my script. E.g., if I edited on a Windows machine and then put the script on a Linux system the extra return characters caused errors in some cases. Copying and pasting code sometimes puts things like tabs that you can't see into the code. That probably isn't the problem, but it's worth looking at your code in an editor using binary mode just to see. (That just occurred to me because you said "After a few editions on a script...")