0

Am getting an error when running this shell script on a Linux machine:

#!/bin/bash
echo "$2 $1"
if [ $1 = "UNSOLICITED_CANCEL" ]; then
    echo "PREVENTIVE MEASURE"
else
    echo "test"
fi
echo "done"

The output I get is:

-bash-3.2$ testShellFile2.sh UNSOLICITED_CANCEL pam2 pam3
: No such file or directoryellFile2.sh: line 1: #!/bin/bash
pam2 UNSOLICITED_CANCEL
/home/shells/testShellFile2.sh: line 13: syntax error: unexpected end of file

Am guessing this is an encoding error, but I have tried every encoding available in Notepad and Notepad++. Although, UTF-8 seems to be the only one that lets it run. Please help, thanks in advance.

heapoverflow
  • 922
  • 3
  • 8
  • 15
  • 3
    `testShellFile2.sh` doesn't run a file from the local directory. That does a path lookup. That's finding a `/home/shells/testShellFile2.sh` it appears. Is that where that file lives? That `testing` message doesn't appear in the snippet you posted so that's unlikely to be the file you are running. That `/home/shells/testShellFile2.sh` file (and likely the one in your snippet) also appears to have DOS line-endings. Run `dos2unix` on both of them. Then try and see if `./testShellFile2.sh ...` gives you different output. – Etan Reisner May 12 '15 at 20:51
  • Also note that you should use `"$1"` in your conditional for robustness. – mklement0 May 12 '15 at 20:58
  • (note that while the question this is marked duplicate of mentions Cygwin in its title, the issue is not at all Cygwin-specific, and nor is its proper fix). – Charles Duffy May 12 '15 at 21:48

0 Answers0