Why is my expect script failing on line 1?

Dennis Day picture Dennis Day · Dec 22, 2010 · Viewed 30.4k times · Source

The very first line of my expect script fails. Here are the entire contents of my script and it fails:

#!/usr/bin/expect -f

And it fails right off the bat with

": no such file or directory

as my response. Expect is in fact installed and is located in /usr/bin/ and I am running this from root. I have no extra spaces or lines before the # sign either. Of course there was more to the script originally but it fails way before it gets to the good stuff.

Answer

Bert F picture Bert F · Dec 22, 2010

Tried it and here is the result: /usr/bin/expect^M: bad interpreter

Is it possible that there's a Windows newline (the "^M") in there that's confusing the script? You can try "od" to see what newline character(s) is after the the "expect" and "tofromdos" or an editor (e.g. emacs in hexl-mode) to remove it. See the man pages for more info.