Reason: when executing a shell script, this error is mainly caused by that the shell script file is in DOS format, that is, the end of each line is marked with a line, while the end of a UNIX file is marked with a line
Solution:
(1) Use the Linux command dos2unix file name to convert the file to UNIX format directly
(2) use the SED command sed – I “s/\ R//” or sed – I “s/^ m//” to directly replace the terminator in UNIX format
(3) VI filename open the file, execute: set FF = UNIX, set the file to UNIX, and then execute: WQ, save it to UNIX format
Several ways to check whether the script file is DOS format or UNIX format
(1) cat – a file name can judge from the display results that the end of the file line in DOS format is ^ m $, and the end of the file line in UNIX format is $
(2) od – t X1 file name if you see 0d 0A characters in the output content, the file is in DOS format, if only 0A, it is in UNIX format
(3) VI filename open the file and execute: set FF. If the file is in DOS format, it will be displayed as fileformat = DOS, if it is uxi, it will be displayed as fileformat = UNIX
Similar Posts:
- [Solved] Python Error: /usr/bin/python^M: bad interpreter: No such file or directory
- syntax error near unexpected token `do [How to Solve]
- Shell script error newline syntax error near unexpected token
- Shell Error: bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory [How to Solve]
- shell :syntax error: unexpected end of file
- How to Solve Error: set ff? /bin/bash^M: bad interpreter: No such file or directory
- shell :syntax error: unexpected end of file
- One line command / usr / bin / Perl ^ m: bad interpreter
- [Solved] Centos7 Execute Script Error: syntax error near unexpected token `fi’
- Conversion to MySQL shell script execution error $’\ R’: command not found