Running shell script reports an error: “syntax error near unexpected token solution ‘”
Today, I wrote a cshell script to run syntax error near unexpected token ‘. There is no problem with the script syntax. Finally, I found the problem
Open your SHELL script file with the command vi -b and you will. You will find an extra ^M at the end of each line of the script.
Old teletypewriters used two characters to start a new line. One character moves the carriage back to the first position (called carriage return, ASCII code 0d), and the other character moves one line on the paper (called line feed, ASCII code 0A). When computers came out, memory used to be very expensive. Some people don’t think it’s necessary to use two characters at the end of a line. UNIX developers decided that they could use a single character to indicate the end of a line. Linux follows UNIX, too. Apple developers have defined the use of. The guys who developed MS-DOS and windows decided to use the old-fashioned.
Because MS-DOS and windows use carriage return + line feed to indicate line feed, you can use VIM under Linux to view the code written in VC under windows. The “^ m” symbol at the end of the line indicates the symbol.
To solve this problem in VIM is very simple. You can kill all “^ m” by using the replacement function in vim. Type the following replacement command line:
1)vi -b setup.sh
2) On the command line & lt; press ESC, and then shift +: Colon & gt; enter% s/^ m// g
Note: the “ m” character in the above command line is not “</ sup>” plus “m”, but generated by “Ctrl + V” and “Ctrl + m” keys.
After this replacement, the save can be executed. Of course, there are other alternatives, such as:
a. Some Linux versions have dos2unix programs that can be used to remove ^ M.
b. Cat filename1 | tr – D “\ R” & gt; newfile removes ^ m to generate a new file, as well as sed command. All replaceable commands can be used to generate a new file.
according to the above, deleting the mshell script will run normally. Later, I asked my colleagues that he had modified the program path in his Windows Notepad, resulting in an extra </ sup> m in each line.
Read More:
- Shell Script syntax error near unexpected token `done’
- [Solved] Linux shell Script Error: syntax error near unexpected token `do
- Ubuntu shell Script syntax error near unexpected token `$‘{\r‘‘
- [Solved] Shell error: syntax error: unexpected end of file
- [Solved] bash: /etc/vimrc: line 15: syntax error near unexpected token `“autocmd“‘
- [Solved] shell Error: Syntax error: “(“ unexpected (expecting “}“)
- Windows writes shell script and executes shell error [Solved]
- [Solved] Linux executes SQL script Error: Syntax error
- [Solved] Bash: Syntax error: redirection unexpected
- Ubuntu: rabbitmq reports an error; Solution error: unable to connect to node rabbit@localhost : nodedown
- Mac opens Terminal and reports an error -bash:: command not found
- [Solved] spdlog reports an error After updating Ubuntu 22.04
- [Solved] An unexpected error has occurred. Conda has prepared the above report.
- [Solved] yum command Error: “except keyboardinterrupt, e: syntax error: invalid syntax”“
- [Solved] sbatch: error: Batch script contains DOS line breaks (\r\n)
- [Solved] Ubuntu Server 18.4 System /etc/sudoers: syntax error near line 32
- Error in Linux running file: bash: $’\r’: command not found
- Linux changing password enter new UNIX password: passwd: authentication token manipulation error
- subprocess installed post-installation script returned error exit status 1
- Shell: How to Get System Current Tme and Format it