For the sh file written with VSCode on Windows platform, the git bash execution is OK. When using the WSL Linux subsystem, an error ^ M: bad interpreter is reported.
Problem recurrence
Execute sh file with Windows Linux subsystem, and error is reported ^M:bad interpreter:No such file or directory
, as shown in the following figure:
On the same Windows platform, the git bash provided with git is used to execute this file without problems.
Causes
For files created by VSCode, CRLF double characters are used by default to represent line breaks. The line breaks used by the current file can be seen in the lower right corner of VSCode:
For Ubuntu in the Linux subsystem, LF single characters are used by default to represent line breaks. When CRLF is encountered, parsing errors are reported during execution.
resolvent
Click in the lower right corner of VSCode CRLF
Button, and then select from the pop-up options LF
Options:
After that, use Ctrl + S
Save the file.