Edg*_*gy1 2 command-line bash scripts
当我尝试为 qb64 安装程序运行 sh 脚本时,此错误发生在 16.04 上。
james@ubuntu:~/qb64$ ./setup_lnx.sh
bash: ./setup_lnx.sh: /bin/bash^M: bad interpreter: No such file or directory
james@ubuntu:~/qb64$Run Code Online (Sandbox Code Playgroud)
您的文件具有DOS/Windows 样式的行尾 (CR LF),但在类 Unix 系统上,只有LF控制字符用作换行符。
附加的CR控制字符显示为^M在您的输出中编码。运行时也可以看到cat -A setup_lnx.sh。
要将行尾从 DOS/Windows 样式转换为 Unix 样式,有一个名为dos2unix. 您使用以下方法安装它:
sudo apt-get install dos2unix
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用以下两种方式简单地转换文件的行尾
dos2unix FILENAME
unix2dos FILENAME
Run Code Online (Sandbox Code Playgroud)
在您的情况下,只需在下面运行此命令,脚本文件将就地转换:
dos2unix setup_lnx.sh
Run Code Online (Sandbox Code Playgroud)
之后 Bash 应该能够正确解释文件。