如何运行(./)位于云中的bash脚本?

问题描述 投票:0回答:3

使用ubuntu 16.04我所做的是:

  1. 使用.sh下载wget https://gist.githubusercontent.com/...脚本
  2. 转动.sh文件可执行文件sudo chmod guo+x sysInit.sh
  3. 通过sudo ./sysInit.sh执行代码

我想知道是否可以直接从网络上运行代码。会是这样的:sudo ./ https://gist.githubusercontent.com/...

有可能吗?

bash ubuntu-16.04 execution
3个回答
2
投票

您可以使用cUrl下载并运行脚本。我不认为它默认安装在Ubuntu上,所以如果你想使用它,你必须首先使用sudo apt-get install curl。要使用sudo下载并运行脚本,请运行

curl -sL https://gist.githubusercontent.com/blah.sh | sudo sh

请注意,这是非常危险的,并且出于安全原因不建议这样做。看到这个相关的问题why-using-curl-sudo-sh-is-not-advised


2
投票

是的,可以使用curl并将结果输送到sh

请尝试以下命令。

curl https://url-to-your-script-file/scriptFile.sh | sh


0
投票

不,sudo只能在shell中的命令行提示符下运行

© www.soinside.com 2019 - 2024. All rights reserved.