The main reason is ^ M
This is caused by different system coding formats: the. Sh. Py file edited in Windows system may have invisible characters, so the above abnormal information will be reported when executing in Linux system. It is usually caused by the different identification of the end of windows line and Linux line
Solution:
1) Conversion in Windows:
Use some editors, such as UltraEdit or EDITPLUS, to encode and convert scripts first, and then put them into Linux for execution. The conversion method is as follows (UltraEdit): File — > Conversions–> DOS-> UNIX is fine
2) Direct replacement under Linux
Sed – I’s/^ m// g ‘file name
3) It can also be converted in Linux
First, make sure that the file has executable permissions
#sh> chmod a+x filename
Then change the file format
#sh> vi filename
Use the following command to view the file format
: set FF or: set fileformat
You can see the following information
Fileformat = DOS or fileformat = UNIX
Use the following command to modify the file format
: set FF = UNIX or: set fileformat = UNIX
: WQ (save and exit)
Finally, execute the file
#sh>./ filename
Similar Posts:
- [Solved] “/bin/bash^M: bad interpreter: No such file or directory”
- syntax error near unexpected token `do [How to Solve]
- shell :syntax error: unexpected end of file
- shell :syntax error: unexpected end of file
- 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]
- How to Solve Error: set ff? /bin/bash^M: bad interpreter: No such file or directory
- 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