Shell错误:/bin/bash^M: bad interpreter: No such file or directory

Table of contents

Error Causes and Symptoms

solution


Error Causes and Symptoms

When executing the shell script, an error is reported: /bin/bash^M: bad interpreter: No such file or directory.
It is because the script file is written on the Windows platform and then executed on the MacOS platform.
On the Windows platform, the file is in dos format, with a newline ending \r\n, while on the MacOS platform, the file is in unix format, with a newline ending \n. Therefore, when running the script file, \r cannot be parsed correctly, resulting in compilation errors and running failures.

solution

On the MacOS platform, open the command line tool to execute the command vim *.sh(edit your script file), then execute the command :set ff=unix, and finally execute :wq(save and exit).

おすすめ

転載: blog.csdn.net/qq_59747594/article/details/132002017