0
I'm on windows 7 using Cygwin.
My script and text file are located in the same directory.
#!/bin/bash
while read name; do
echo "Name read from file - $name"
done < /home/Matt/servers.txt
I 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 it's because I'm on windows and using Cygwin.
Do you mean it worked on Unix? – golimar – 2013-07-01T15:35:26.333
@golimar no never tested it – mkrouse – 2013-07-01T15:42:23.710
why don't you do a for loop? IMHO it would be much more readable (sorry it does not answer the question) – pataluc – 2013-07-01T16:03:18.850
@pataluc: Because
while read...
is often the recommended method. – user1686 – 2013-07-01T16:10:02.007Could you post the file you are reading from? Also try adding
;
after the echo command and the done, just in case. – terdon – 2013-07-01T16:31:02.0601Check the script for DOS-style line endings by printing it with
cat -v /path/to/script
and looking for "^M" at the end of lines." This doesn't really look like the errors I'd expect from this, but with Cygwin it's best to check. – Gordon Davisson – 2013-07-02T07:28:19.627I used this command to flip my script from the windows style endings. sed -i 's/\r$//' script – mkrouse – 2013-07-02T14:47:24.933