Sometimes an error will be reported when executing the script:
[[email protected] shell]# sh -x test. sh + $ ' \r ' : command not found test. sh : line 37 : syntax error: unexpected end of file
reasons may be:
The text editor is the file written by Notepad or other editors under windows, and it runs in the cygwin simulation LINUX software environment.
The file format difference between DOS and Linux is caused.
The text file under DOS uses \r\n as the line break mark, expressed in hexadecimal is 0D 0A. The text file under Unix uses \n as a line break mark, which is 0A in hexadecimal.
[In windows, the two symbols used for line feed, carriage return \r, line feed symbol \n, under linux, only one symbol \n is enough .]
A text file in DOS format under Linux will display ^M at the end of the line when opened with a lower version of vi. Of course, you may not be able to see it, but in vi, the format of the file will be displayed below, “M.txt “[dos] 8L, 72C means a dos file format.
Use the following command to set the file format to unix format to solve the above error
vi test. sh :set fileformat = unix :wq
Why can’t the script edited under windows be directly copied to the unix system and run directly?
Linux executes SHELL script error “syntax error near unexpected token `in”
long long ago….. Old teletypewriters used two characters to start a new line. One character moves the carriage back to the first position (called carriage return, <CR>, ASCII code 0D), and another character moves the paper up one line (called line feed, <LF>, ASCII code 0A). When computers came out, memory used to be very expensive. Some people think it is unnecessary to use two characters to indicate the end of a line. Unix developers decided that they could use a character to indicate the end of a line, Linux followed Unix, and it was also <LF>. Apple developers specified the use of <CR>. The guys who developed MS-DOS and Windows decided to use the old <CR><LF>.
Because MS-DOS and Windows use carriage return + line feed to represent line feed, so under Linux, use Vim to view the code written in VC under Windows. The “^M” symbol at the end of the line indicates a symbol.
- Running shell script reports an error: “syntax error near unexpected token solution ‘”
- Shell Script syntax error near unexpected token `done’
- Error in Linux running file: bash: $’\r’: command not found
- [Solved] shc -f xxx.sh shc: invalid first line in scrip
- How to Uncompress 7z files on Ubuntu, Debian, Fedora
- Docker Startup Error: standard_init_linux.go:211: exec user process caused “no such file or directory”
- C#: How to Use Itextsharp to Manipulate PDF Files
- [. Net] Several Ways to Generate GUID
- How to Use Apt get Command Under Mac OSX
- [Solved] /var/tmp/rpm-tmp. The tmp file cannot be found when the installation fails
- Solutions to errors in installing xunsearch engine in centos8.0
- subprocess installed post-installation script returned error exit status 1
- [Linux] undefined reference to `itoa’
- Linux: How to Fix undefined reference to `itoa’
- Sublime text 3 compiles and executes C/C++ programs directly
- Mac opens Terminal and reports an error -bash:: command not found
- Git-126.96.36.199-64-bit Error: cannot spawn git: Function not implemented
- Chinese garbled problem when running. C file in Linux
- [Solved] CUDA driver version is insufficient for CUDA runtime version