Running shell script in Cygwin terminal

I am new to shell scripting.
I tried to run a simple shell script using Cygwin terminal in Win XP env.
The script I have written is as follows -

#!/bin/bash
a=5
[[ "$a"== "5" ]] && echo "true" || echo "false"

But when I execute the script, getting some confusing error. The error I am getting are -

first_prog.sh: line 2: $'\r': command not found
first_prog.sh: line 4: $'\r': command not found
first_prog.sh: line 5: conditional binary operator expected
first_prog.sh: line 5: syntax error near `"5"'
first_prog.sh: line 5: `[[ "$a"== "5" ]] && echo "true" || echo "false"'

Though the commands are working fine individually when run from terminal, but not in the shell script. Do I need any settings in the Cygwin terminal?
I am using the BASH shell.
Please suggests.
Thanks in advance.

Are you editing this script with notepad? This will fill the file with garbage carriage returns which the shell will consider as part of shell statements, ruining them. Try 'dos2unix' to fix the script.

1 Like

One thing I noticed is that there seems not to be a space between the double equal in the test and the "5" (hard to see without code tags).

#!/bin/bash
 a=5
 [[ "$a" == "5" ]] && echo "true" || echo "false"
#       ^ Need space here

Corona688's concerns still apply, but this is certainly causing issues too.

1 Like

Thanks Corona and Agama, yes both were the problem.
Once I converted to unix format using dos2unix, I identified the other problem as well. Now it is working fine.