I'm on windows 7 using Cygwin.My script and text file are located in the same directory.#!/bin/bashwhile read name; doecho Name read from file - $namedone < /home/Matt/servers.txtI get this error and I don't know why because this is correct while loop syntax..?u0146121@U0146121-TPD-A ~/Matt$ ./script.sh./script.sh: line 4: syntax error near unexpected token `done'./script.sh: line 4: `done < /home/Matt/servers.txt'Can anybody tell me what I'm doing wrong? I think its because I'm on windows and using Cygwin.
Trouble with read line script in Cygwin
bash;shell script;cygwin
As pointed out by ott--, your script has CR LF line endings. This is more visible with od.$ od -c script0000000   #   !   /   b   i   n   /   b   a   s   h  \r  \n   w   h   i0000020   l   e       r   e   a   d       n   a   m   e   ;       d   o0000040  \r  \n   e   c   h   o          N   a   m   e       r   e   a0000060   d       f   r   o   m       f   i   l   e       -       $   n0000100   a   m   e     \r  \n   d   o   n   e       <       /   h   o0000120   m   e   /   M   a   t   t   /   s   e   r   v   e   r   s   .0000140   t   x   t  \r  \n0000145As you can see, you have \r (carriage return) and \n (line feed) characters at the end of each line where you should only have \n characters. This is a result of a compatibility issue between Windows and *nix systems. Bash has difficulty dealing with the \r characters. You can fix your script by using a utility like dos2unix or by running the following line.sed -i 's/\r$//' script