1

I seem to be having a weird problem, the solution for which might be dead simple and I am just being blind.

My development environment is Windows. I create a deployment archive file, within which contains a shell script file (called install.sh). I sftp this archive over to a linux environment, untar it and try to run execute the script (after chmod to make it executable) and I get this error:

syntax error: unexpected end of file

I don't notice any errors in the file. I delete this file, create a new install.sh, copy over the exact contents from my Windows env, chmod it again, run it again and this time it runs fine!

I have no idea why it does not run the first time I untar it. Any help appreciated!

starman1979
  • 974
  • 4
  • 12
  • 33

2 Answers2

5

Check your file:

cat --show-nonprinting file

Remove carriage returns from Windows/DOS:

tr -d "\r" < file > fixed_file
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Looks like it was carriage returns that was causing it. However I couldn't use the tr, I used this instead: sed -i -e 's/\r//g' install.sh – starman1979 Aug 13 '15 at 20:26
2

Linux and Windows uses different end of line (CL or CLRF), or maybe it's an encoding problem. You should check the differences between the running sh and the non-running one.