Sometimes an error is reported when executing a script:
[root@host1 shell]# sh -x test.sh + $'\r' : command not found test.sh: line 37: syntax error: unexpected end of file
The reason may be:
Text editing is written through Notepad or other editors under windows. This file runs in cygwin simulated linux software environment
Solution:
The file format difference between dos and Linux
Text files under DOS take \ R \ n as the line break flag, expressed in hexadecimal, which is 0d 0A. Text files under UNIX take \ n as the line break flag, which is expressed in hexadecimal, which is 0A
[in windows, two symbols for line feed, enter \ R, line feed symbol \ n, only one symbol is required under Linux .]
Text files in DOS format will display ^ m at the end of the line when they are opened with a lower version of VI under Linux. Of course, they may not be visible, but when they are opened with VI, the format of this file will be displayed below, “m.txt” [DOS] 8L, 72C indicates that it is a DOS file format
Solution:
Use the following command to set the file format to UNIX format to solve the above error
vi test.sh :set fileformat=unix :wq
Similar Posts:
- shell :syntax error: unexpected end of file
- [Solved] “/bin/bash^M: bad interpreter: No such file or directory”
- Shell script error newline syntax error near unexpected token
- syntax error near unexpected token `do [How to Solve]
- [Solved] Python Error: /usr/bin/python^M: bad interpreter: No such file or directory
- Conversion to MySQL shell script execution error $’\ R’: command not found
- The difference between UTF-8 and utf-8-sig
- How to Solve Error: set ff? /bin/bash^M: bad interpreter: No such file or directory
- Error reason for adding PNG pictures in Android studio
- Git LS files displays the current file status