3

I have this simple Bash script:

#!/bin/bash
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!

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
ComFreek
  • 150
  • 1
  • 9
  • 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

1 Answers1

2

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

ComFreek
  • 150
  • 1
  • 9
  • 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: http://stackoverflow.com/questions/13135808/system-io-filewritealllines-adds-newline-at-the-end – ComFreek Oct 30 '12 at 09:16