Today wrote a shell script, the old error check the basic syntax and did not find errors. Later after the settlement of Baidu, and now summarized as follows.
error phenomenon : Execute shell script, old error "syntax error near unexpected token '"
workaround : vim-b example.sh Open the file, found that the file at the end of each line of a ^m, the problem in the use of Vim example.sh view is invisible, only by error to determine the use of vim-b to find the problem.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8D/7C/wKioL1idxdbzc0yuAAATvQhmgZ0815.png "title=" Capture 1. PNG "alt=" Wkiol1idxdbzc0yuaaatvqhmgz0815.png "/>650) this.width=650; src=" https://s1.51cto.com/wyfs02/M02/8D/ 7c/wkiol1idxkdhtwrcaaajrgbrjzk867.png "title=" Capture 2. PNG "alt=" Wkiol1idxkdhtwrcaaajrgbrjzk867.png "/>
Because MS-DOS and windows are carriage return + newline to represent line breaks, so under Linux with Vim to see the code written in the VC under Windows, the "^m" symbol after the end of the line, indicating the character.
To solve this problem in vim, it is easy to use the Replace function in Vim to kill "^m" and type the following command line:
1) vi-b setup.sh
2) in the command edit line < just: Press ESC and shift+: colon > Input:%s/^m//g
Note: the "^m" character in the above command line is not "^" plus "M", but is generated by the "Ctrl + V" and "ctrl+m" keys.
Once this is replaced, the save can be executed. And of course there are other ways to replace them, such as:
Some Linux versions have Dos2unix programs that can be used to remove ^m.
Error reason : When writing a script, the script was edited using UltraEdit, and then there was the version of the WinDOS computer, which was then transferred to the Linux system for execution. It is possible that the default DOS format is enabled when storing text.
This article is from the "Small Knowledge Base" blog, make sure to keep this source http://babyhanggege.blog.51cto.com/11741640/1896833
Linux Shell pin This newspaper wrong "syntax error near unexpected token '" solution