60

I'm trying to compile the NIST Biometric Image Software, and I have been having trouble all day. I finally got the source checked out right, and I installed cygwin with no problems (I have used it in the past), but when I went to compile, I get this error:

 $  sh setup.sh </cygdrive/c/NBIS> [--without-X11]
 setup.sh: line 94: syntax error near unexpected token `$'in\r''
 'etup.sh: line 94: `    case $1 in

Now I'm sure any advanced coder would head to the setup.sh and look for problems, but I'm not really much of a coder (I'm only compiling this because there are no pre-compiled packages) so I don't know what to do. I didn't install any libraries with cygwin, I just left everything default. I'm trying to follow the NBIS manual, but I don't really understand it that well and so I'm struggling badly. Maybye taking a look at it you may notice something I missed: http://www.nist.gov/customcf/get_pdf.cfm?pub_id=51097

David
  • 621
  • 1
  • 5
  • 4
  • Everyone here seems to suggest that the answer is to use linux style newlines, anyone know what to do if you need to run a bash script with windows style newlines? – Groostav Mar 27 '20 at 21:22

5 Answers5

89

run

sed -i 's/\r//' setup.sh

to fix your line endings

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Frank Hayward
  • 1,077
  • 7
  • 8
74

That's a symptom of line-ending mismatch.

To convert setup.sh to Unix line endings on Cygwin, use

dos2unix setup.sh
Jens
  • 69,818
  • 15
  • 125
  • 179
18

Easy way to convert example.sh file to unix is use NotePad++ (Edit>EOL Conversion>UNIX/OSX Format)

You can also set the default EOL in notepad++ (Settings>Preferences>New Document/Default Directory>select Unix/OSX under the Format box)

Eftekhari
  • 1,001
  • 1
  • 19
  • 37
  • 2
    Thanks, worked for me. I encountered this as I was compiling Shell scripts on Linux Ubuntu Subsystem in Windows 10 but typing the commands in notepad++ instead of vim or via nano. – iamjoshua Mar 14 '19 at 19:53
15

In pycharm you can quickly change the line endings by clicking on the letters CRLF at the bottom right of the screen and selecting LF.

pycharm line endings location

Daniel Butler
  • 3,239
  • 2
  • 24
  • 37
11

Windows uses two characters (CR and LF, or \r\n) to mark the end of a line in a text file. Unix, Linux, and (by default) Cygwin use a single LF or '\n' character. Some Cygwin tools are able to deal with either format, but sh typically can't.

It looks like setup.sh uses Windows-style line endings -- or at least line 94 does.

I didn't find the download for the sources, but if they're distributed as a zip file, you might need to extract them using the Cygwin unzip command with the -a option, so any line endings are automatically converted.

But I suspect there's more to it than that. The distributed setup.sh file shouldn't have had any Windows-style line endings in the first place, and if it did, I don't know why the problem wouldn't show up until line 94.

If you can post the URL for the source download, I'll take a look at setup.exe.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631