syntax error near unexpected token `$'in\r''

syntax error near unexpected token python
syntax error near unexpected token c
syntax error near unexpected token `$'do\r''
syntax error near unexpected token done
bash: syntax error near unexpected token git
syntax error near unexpected token int main
syntax error near unexpected token mysql
syntax error near unexpected token then

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 </cygdrive/c/NBIS> [--without-X11] line 94: syntax error near unexpected token `$'in\r''
 ' line 94: `    case $1 in

Now I'm sure any advanced coder would head to the 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:

That's a symptom of line-ending mismatch.

To convert to Unix line endings on Cygwin, use


scripts - bash: syntax error near unexpected token `(', You should use single quotes ' or double quotes " around the URL in this case (​and in general): Syntax Error near unexpected token ` (‘ This error message also surfaces when you are entering commands in the Linux command line for everyday tasks such as copying files manually etc. The main reasons why this error message occurs is either because of bad syntax or problem of the OS in interpreting another system’s commands/shell.


sed -i 's/\r//'

to fix your line endings

SOLVED: 'syntax error near unexpected token `do', I'm Jason, a junior QA at PaperCut. This is the story about the time I solved “​syntax error near unexpected token `do”. Settle in – it's a  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Easy way to convert 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)

Situation Syntax Error near unexpected token `(' on Take Action , below syntax error caused by the attribute variable substitution in the take action -c: line 0: syntax error near unexpected token  Check question is a bit old but for anyone else encountering such syntax errors, shellcheck is a great tool. – M-J Feb 22 '19 at 20: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 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 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.

Syntax error near unexpected token `(', Process substitution is not specified by POSIX, so not all POSIX shell support it, only some shells like bash , zsh , ksh88 , ksh93 support. In Centos system  Works fine for me with 4.1.5(1)-release, might be something in your old version or perhaps some other if block open? – Chris Morgan Nov 15 '10 at 7:08

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.

syntax error near unexpected token ' - bash, It could be a file encoding issue. I have encountered file type encoding issues when working on files between different operating systems and  To display a certain line from the outfile, you can use 'grep' or 'awk' for example.----- Post updated at 09:06 ----- Previous update was at 09:03 -----Just recongnized, that NEWFILE does not get set in the else-part just before the chmod.

Shell Script Error "syntax error near unexpected token", SYMPTOM:Syntax error near unexpected token. SYMPTOM:Bad interpreter. SYMPTOM:Attempting to run a bash shell script received from another source  syntax error near unexpected token `else' Shell Script echo "please enter username" read user_name echo "please enter password" read -s pass echo ${ORACLE_SID} SID=${ORACLE_SID} if ["${ORACLE_SID}" != 'Test'] then sqlplus -s -l $USER_NAME/$PASS@$SID <<EOF copy from scott/tiger@orcl insert EMP using select * from EMP exit EOF else echo "Cannot copy" fi

I'm getting a bash: syntax error near unexpected token '(', bash: syntax error near unexpected token '('. You need to escape the brackets: mv hiscore\(pre_mame0133u1\).dat  Jason Clarke - Product Tester. Jason’s what we call a PaperCut ‘OG’. Over his 9 years with us, he’s hung out in support and internal IT before becoming a customer evangelist and product tester.

A bug "/bin/sh: -c: line 0: syntax error near unexpected token `('" #948, when I run "horovodrun -np 4 -H localhost:4 python3 " then a bug "/bin/sh: -c: line 0: syntax error near unexpected  Shop Devices, Apparel, Books, Music & More. Free Shipping on Qualified Orders.

  • 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?
  • 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.