如何 运行 (./) 位于云端的 bash 脚本?
How to run (./) a bash script located in the cloud?
使用 ubuntu 16.04 我所做的是:
- 使用
wget https://gist.githubusercontent.com/...
下载 .sh
脚本
- 将
.sh
文件变为可执行文件 sudo chmod guo+x sysInit.sh
- 通过
sudo ./sysInit.sh
执行代码
我想知道是否可以 运行 直接从 Web 获取代码。
会是这样的:sudo ./ https://gist.githubusercontent.com/...
.
可以吗?
不,sudo 只能在 shell
中的命令行提示符下工作
是的,可以使用 curl
并将结果通过管道传输到 sh
。
尝试以下命令。
curl https://url-to-your-script-file/scriptFile.sh | sh
您可以使用 cUrl 下载并 运行 您的脚本。我不认为它默认安装在 Ubuntu 上,所以如果你想使用它,你必须先安装 sudo apt-get install curl
。要使用 sudo 下载并 运行 你的脚本 运行
curl -sL https://gist.githubusercontent.com/blah.sh | sudo sh
请注意,这是非常危险的,出于安全原因不建议这样做。请参阅此相关问题
使用 ubuntu 16.04 我所做的是:
- 使用
wget https://gist.githubusercontent.com/...
下载 - 将
.sh
文件变为可执行文件sudo chmod guo+x sysInit.sh
- 通过
sudo ./sysInit.sh
执行代码
.sh
脚本
我想知道是否可以 运行 直接从 Web 获取代码。
会是这样的:sudo ./ https://gist.githubusercontent.com/...
.
可以吗?
不,sudo 只能在 shell
中的命令行提示符下工作是的,可以使用 curl
并将结果通过管道传输到 sh
。
尝试以下命令。
curl https://url-to-your-script-file/scriptFile.sh | sh
您可以使用 cUrl 下载并 运行 您的脚本。我不认为它默认安装在 Ubuntu 上,所以如果你想使用它,你必须先安装 sudo apt-get install curl
。要使用 sudo 下载并 运行 你的脚本 运行
curl -sL https://gist.githubusercontent.com/blah.sh | sudo sh
请注意,这是非常危险的,出于安全原因不建议这样做。请参阅此相关问题