Write a sh file directly on Pycharm and run it on the server to report an error, such as a title.
Then, vim on the server takes all line breaks, whitespaces, and retyping is invalid
Finally, the reasons for the errors and two solutions are summarized.
The reason:
As many blogs have explained, because of the difference between line breaks in Windows and Linux systems, in Windows the line break is ‘\r\n’ whereas in Linux it is ‘\n’, now we understand the meaning of error reporting. For code written in Windows format to be executed on Linux, there is an extra ‘\r’, this is the reason: “Syntax error near token ‘$’do\r'” ”
Visually, run the command and change your file name.
Then, vim on the server takes all line breaks, whitespaces, and retyping is invalid
Finally, the reasons for the errors and two solutions are summarized.
The reason:
As many blogs have explained, because of the difference between line breaks in Windows and Linux systems, in Windows the line break is ‘\r\n’ whereas in Linux it is ‘\n’, now we understand the meaning of error reporting. For code written in Windows format to be executed on Linux, there is an extra ‘\r’, this is the reason: “Syntax error near token ‘$’do\r'” ”
Visually, run the command and change your file name.
cat -v bb.sh
There will be:
for i in 1 2 3;^M
do^M
echo"aa"^M
If you have this to the M, that means you’re a window newline, and if you’re a Linux newline, you’re not going to have a to the M at the end.
The solution
1. Novice White, simple violence
Cat first:
cat bb.sh
Output:
for i in 1 2 3;
do
echo"aa"
Then select the left key on CMD to copy it, then vim creates a new file, switch to the writing mode (press I), and then right-click to copy once, save and exit.
2. Replace ‘\r’ with sed.
sed 's/\r//' bb.sh > aa.sh
The first S means a replacement, which is to replace the /r in BB.sh with a ‘ ‘and save the replacement to the file aa.sh.
The above
Read More:
- Solve the problem of syntax error: unexpected end of file or syntax error near unexpected token ` fi ‘error
- Solve syntax error: unexpected end of file or /bin/bash^m: bad interpeneter: no match file or directory
- Solve the problem of shell script “syntax error near unexpected token `fi’”.
- Syntax error near unexpected token `newline’script cannot be executed
- syntax error near unexpected token `else’
- Shell script syntax error near unexpected token ‘$’Do
- syntax error near unexpected token `then’ problem solution
- Unexpected syntax error: unexpected token<
- Shell script execution error: “syntax error near unexpected token”
- bash: /opt/ros/kinetic/ setup.bash : there is no file or directory
- Uncaught syntax error: unexpected token ‘< 0‘
- Docker machine install syntax error near unexpected token ‘newline’! DOCTYPE HTML problem resolution
- Syntax error: unexpected token in uni app project compilation
- Syntax error: typeerror: this.getoptions is not a function an error is reported when the. SCSS file is imported globally
- The Linux terminal appears bash: setup.bash : no such file or directory, and. Bashrc file
- When installing ROS: bash / opt / ROS / kinetic/ setup.bash : there is no file or directory
- Error: unexpected syntax error: unexpected token<
- Syntax error: unexpected end of file problem [two solutions]
- Error: syntax error – unexpected token P in JSON at position 0
- Baidu editor echo JS error uncaught syntax error: invalid or unexpected token