我有一个名为 setup_wsl.sh
的 shell 脚本其中包含:
#!/bin/bash
echo "hai"
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
当我在 WSL 中将脚本作为 ./setup_wsl.sh 运行时(安装的发行版是 ubuntu 18.04),会出现以下错误:
hai
E: Invalid operation update
E: Unable to locate package
./setup_wsl.sh: 4: ./setup_wsl.sh: apt-transport-https: not found
./setup_wsl.sh: 5: ./setup_wsl.sh: ca-certificates: not found
curl: (3) Illegal characters found in URL
./setup_wsl.sh: 7: ./setup_wsl.sh: gnupg-agent: not found
: not found ./setup_wsl.sh: software-properties-common
: not found ./setup_wsl.sh:
脚本的第一个命令工作正常,因为它给出了输出“hai”。
有人可以帮我找出发生这些错误的原因吗?
最佳答案
这是因为 Windows 中的回车。
使用文本编辑器切换到 LF 小车并保存新小车以运行脚本
或 sed -i -e 's/\r$//' setup_wsl.sh
关于file - 在 WSL 中运行 shell 脚本时出现 "E: Invalid operation update"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55258430/