Cygwin errors

I'm not sure if this is the right place to post this or should I even be posting this here but here is my problem. I've recently installed Cygwin on my windows laptop so that I can run shell scripts. However I'm getting lots of errors with most lines of code in my scripts although the syntax is correct. I've left a message with the Cygwin mailing list (closest thing to a forum) but I have not received any reply.

I have a very simple script:

#!/bin/bash
#
 
FRUIT="kiwi"
 
case "$FRUIT" in 
"apple") echo "Apple" ;;
"banana") echo "Banana" ;;
"kiwi") echo "Kiwi" ;;
esac

/usr/bin/debug.sh: line 3: $'\r': command not found
/usr/bin/debug.sh: line 5: $'\r': command not found
/usr/bin/debug.sh: line 6: syntax error near unexpected token 'newline'
/usr/bin/debug.sh: line 6: 'case "$FRUIT" in

The first 2 errors (lines 3 & 5) always occur when there is a blank line. I've no idea why this is a problem.

Please help!

\r is added by your text editor (Windows text editor?) at the end of each line (carriage return)
You have to configure it to NOT write \r at the end of the line.

Thanks for that. How do I configure it to not write \r?

The utility dos2unix converts files with DOS/Windows carriage control to UNIX carriage control. cygwin's unix2dos simply takes a file and converts it without redirecection needed.

dos2unix myscript.sh
# you should always add execution permissions to a new script
chmod +x myscript.sh

Thanks for that. It's working perfectly now :slight_smile:

The basic notepad.exe (the one provided with windows) is not configurable in this regard. You have to use notepad2, notepad++ or another alternative to do so

I'm using notepad++. Thanks

I find though that every time I edit the script I have to run the dos2unix again. Is there any way to permanently keep it converted to Unix format?

use vi/vim under cygwin...

I am also use Notepad++. but never got carriage return...

vi and vim are causing the same problems.