After you write a Linux shell script under Windows with Notepad, execute the syntax error near unexpected token errors
Problem principle:
Online search for a long time, find the reason, the original is the problem of return, each system of the return line character is not the same.
The window system's Notepad return is CR and LF
Linux system Notepad enter is LF
Mac System Notepad Enter is CR
Writing programs under Windows Linux executes it doesn't know what CR is. So there will be syntax error near unexpected token errors.
All characters in the text can be viewed in a Linux environment by Vi-b
Workaround:
1:vi Editor Workaround
Just remove the return line CR (^m display in vi-b) in the Linux environment.
Here CR is not sure is ^v or ^m, under Linux can not directly match CR (in Vi-b is ^m display).
So to use or match:%s/[^v|^m]$//g to match the CR (in Vi-b is the ^m display), followed by the text is the return line under Linux.
2: Notepad workaround
It seems that Windows comes with Notepad and WordPad can't convert text format, so it doesn't solve the problem.
I am using the notepad++ text editor. You can convert to UNIX format in edit->eol conversion->.
Linux Shell-syntax error near unexpected token error