63

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

2
  • 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, 2020 at 21:22
  • You know the line. You know the problem (a carriage return character after the wordin). Why don't you just have a look at the file using a decent hex editor? BTW, @Groostav: I'm not convinced that the problem here is simply a script with CRLF line endings. If this were the case, it would more likely have already bailed out already earlier. Nov 28, 2023 at 7:31

6 Answers 6

94

run

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

to fix your line endings

1
  • sed -i 's/\r//' setup.sh works!!
    – Frank Guo
    Jan 1, 2022 at 16:52
75

That's a symptom of line-ending mismatch.

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

dos2unix setup.sh
20

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)

1
  • 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, 2019 at 19:53
17

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

3
  • 1
    Yes it's the fast way to change CRLF to LF using VS Code Jun 29, 2022 at 8:26
  • 1
    It also works on PHPStorm, then a composer build is enought. Sep 7, 2023 at 9:31
  • 1
    Yeah, it works for any Jetbrains IDE that I am aware of (IntelliJ, WebStorm, PHPStorm, PyCharm, etc.) Sep 7, 2023 at 20:31
12

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.

0

I used to have the same issue but I solved it using notepad++

Install Notepad++, Open your shell code using Notepad++, Go to the "Edit" menu, Select "EOL Conversion, Choose the "Unix (LF)" option and it should be fixed

or if you use Visual Studio Code you can change CRLF to LF

Visual Studio Code

Notepad++

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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