我们有 10 台装有某些版本的 Ubuntu 且只能远程访问的 PC。在对自定义软件进行一些升级时,我没有注意到某些脚本中的行尾是 Windows 版本 (CR+LF) 而不是 Unix 版本 (LF)。所以现在当我想启动脚本时,它给出了一个错误:
bash: /usr/local/bin/portsee: /usr/bin/python^M: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)
有没有办法从终端更改脚本中的所有行结尾。问题是我无法在这组 PC 上安装任何新软件。
我在我的 Windows 机器上安装了Ubuntu bash,所以我可以在工作之外测试 linux 脚本。我创建了一个非常简单的脚本,其中包含基本的“hello world”和一个更改目录 (cd),但是在执行时会显示 hello world。它在 cd 到目录行上出错。
这是错误:
$ ./test.sh
hello world
zipping away
./test.sh: line 6: cd: $'/home/fjaffer/temp\r\r': No such file or directory
./test.sh: line 7: $'\r': command not found
ffr@DP-PC:~$
Run Code Online (Sandbox Code Playgroud)
我的脚本test.sh如下:
#!/bin/bash
echo "hello world"
echo "zipping away"
dir=/home/fjaffer/temp
cd $dir
Run Code Online (Sandbox Code Playgroud)
请指教?谢谢你。
当我尝试在 Ubuntu WSL 安装中的 Windows 上运行使用 Visual Studio Code 制作的脚本时,出现错误:
line 2: $'\r': command not found
Run Code Online (Sandbox Code Playgroud)
我遇到了以下问题:
如何修复在 WSL 中运行 Bash 脚本的“$'\r': command not found”错误?.
这一切都说得通,但是在 Windows 上的 Visual Studio Code 上有没有一种方法/设置不必每次都使用 dos2unix 实用程序?