I have this simple Bash script:

java -jar ClosureCompiler/compiler.jar --js ../src/typescript.js --js ../src/ts-compiler.js --js_output_file TSCompiler.js

I'm getting this error when I try to run the script using build.sh in the MSYS environment under Windows (64-bit!):

./build.sh: ./build.sh: cannot execute binary file

But the command itself works if I type it directly into the command line window!

  • 1
    Whatever the problem is, it's with the script itself and not the command in the script. What text editor did you save the script with, maybe it has lines ending in CR/LF instead of LF? – Random832 Oct 29 '12 at 19:55
  • @Random832 I have already changed them to LF using Notepad++. – ComFreek Oct 29 '12 at 20:06
  • That's a weird error message: build.sh is telling you it can't run build.sh? What's the output of file build.sh? – jw013 Oct 29 '12 at 20:12

The file was encoded in UCS-2 Little Endian !
Changing the encoding to UTF-8 without BOM resolved the issue.

| improve this answer | |
  • 1
    Msys copes with Windows line endings. Cygwin doesn't. Neither copes with weird Windows formats that aren't ASCII-based, such as UCS-2 or UTF-8 with a U+FEFF prepended (which Windows calls a BOM). – Gilles 'SO- stop being evil' Oct 29 '12 at 22:30
  • @Gilles I've just tried it using Cygwin: it doesn't work - as you said! The problem is that PowerShell adds a CRLF EOL symbol at the end of the file. Here's my question at SO if someone can help: stackoverflow.com/questions/13135808/… – ComFreek Oct 30 '12 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.