执行 curl 获取的脚本时将参数传递给 bash [英] Passing parameters to bash when executing a script fetched by curl

查看:32
本文介绍了执行 curl 获取的脚本时将参数传递给 bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何像这样执行远程 Bash 脚本:

I know how to execute remote Bash scripts like this:

curl http://example.com/script.sh | bash

bash < <( curl http://example.com/script.sh )

给出相同的结果.

但是如果我需要将 arguments 传递给 bash 脚本怎么办?当脚本保存在本地时是可能的:

But what if I need to pass arguments to the bash script? It's possible when the script is saved locally:

./script.sh argument1 argument2

我尝试了几种这样的可能性,但没有成功:

I tried several possibilities like this one, without success:

bash < <( curl http://example.com/script.sh ) argument1 argument2

推荐答案

try

curl http://foo.com/script.sh | bash -s arg1 arg2

bash 手册说:

如果存在 -s 选项,或者在选项处理后没有剩余参数,则从标准输入读取命令.此选项允许在调用交互式 shell 时设置位置参数.

If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.

这篇关于执行 curl 获取的脚本时将参数传递给 bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆