当我在 Vim 中打开文件时,我看到奇怪的^M
字符。
不幸的是,世界上最受欢迎的搜索引擎对查询中的特殊字符表现不佳,所以我在这里问:
这是什么^M
性格?
怎么可能到了那里?
我该如何摆脱它?
我已经创建了一个 bash 脚本,但是当我尝试执行它时,我得到
#!/bin/bash no such file or directory
Run Code Online (Sandbox Code Playgroud)
我需要运行命令:bash script.sh
让它工作。
我怎样才能解决这个问题?
为什么以下基本脚本的 shebang 部分不起作用:
$ cat hello.sh
#! /bin/sh
echo Hello
$ ./hello.sh
bash: ./hello.sh: /bin/sh^M: bad interpreter: No such file or directory
$ cat hello.py
#! /usr/bin/env python3
print("Hello")
$ ./hello.py
: No such file or directory
Run Code Online (Sandbox Code Playgroud)
而手动调用解释器正在工作:
$ sh hello.sh
Hello
$ python3 hello.py
Hello
Run Code Online (Sandbox Code Playgroud)