wget 并在一行中运行/删除 bash 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12787501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:29:22  来源:igfitidea点击:

wget and run/remove bash script in one line

bashshellwget

提问by amanada.williams

wget http://sitehere.com/install.sh -v -O install.sh; rm -rf install.sh

That runs the script after download right and then removes it?

下载后运行脚本然后删除它?

回答by helderco

I like to pipe it into sh. No need to create and remove file locally.

我喜欢用管道将它导入 sh。无需在本地创建和删除文件。

wget http://sitehere.com/install.sh -O - | sh

wget http://sitehere.com/install.sh -O - | sh

回答by Janito Vaqueiro Ferreira Filho

I think you might need to actually execute it:

我认为您可能需要实际执行它:

wget http://sitehere.com/install.sh -v -O install.sh; ./install.sh; rm -rf install.sh

Also, if you want a little more robustness, you can use &&to separate commands, which will only attempt to execute the next command if the previous one succeeds:

另外,如果你想要更健壮一点,你可以使用&&分隔命令,如果前一个命令成功,它只会尝试执行下一个命令:

wget http://sitehere.com/install.sh -v -O install.sh && ./install.sh; rm -rf install.sh

回答by bnjmn

I think this is the best way to do it:

我认为这是最好的方法:

wget -Nnv http://sitehere.com/install.sh && bash install.sh; rm -f install.sh

Breakdown:

分解:

  • -Nor --timestampingwill only download the file if it is newer on the server
  • -nvor --no-verboseminimizes output, or -q/ --quietfor no "wget" output at all
  • &&will only execute the second command if the first succeeds
  • use bash(or sh) to execute the script assuming it is a script (or shell script); no need to chmod +x
  • rm -f(or --force) the file regardless of what happens (even if it's not there)
  • It's not necessary to use the -Ooption with wgetin this scenario. It is redundant unless you would like to use a different temporary file name than install.sh
  • -N或者--timestamping只下载服务器上较新的文件
  • -nv--no-verbose最小化输出,或-q/--quiet根本没有 " wget" 输出
  • &&如果第一个命令成功,只会执行第二个命令
  • 使用bash(或sh) 执行脚本,假设它是一个脚本(或 shell 脚本);没有必要chmod +x
  • rm -f(或--force)无论发生什么的文件(即使它不存在)
  • 在这种情况下,没有必要使用-Owith 选项wget。它是多余的,除非您想使用不同的临时文件名install.sh

回答by divanshu

You are downloading in the first statement and removing in the last statement. You need to add a line to excute the file by adding :

您正在第一个语句中下载并在最后一个语句中删除。您需要添加一行以通过添加以下内容来执行文件:

./install.sh