Wednesday, June 25, 2014

Solving Error: “syntax error near unexpected token”

Detail Error:
: command not found
: command not found
'/ line 3: syntax error near unexpected token `{
'/ line 3: `function stop_channels(){

was thrown when I run

The issue was I opened the .sh (shell script) in Windows OS and Windows changed the end of the line to CRLF

I found this out by running

cat --show-nonprinting filename.extension

cat --show-nonprinting

Or open the file in Notepad++ and click on the button circled in the figure below.

windows vs linux.PNG

Then, I converted it using

dos2unix filename.extension
[Install dos2unix if required]

dos2unix myfile.txt