curl 脚本并直接执行,如何传入参数

2015-09-07 17:55:57 +08:00
 atom
如果某个脚本托管在服务器上,大家一般会酷炫地直接用管道方式来下载并执行脚本

$ cat yourscript.sh
#! /bin/sh
echo "receive params:[$@]"


curl -fsSL "http://somewhere/yourscript.sh" | /bin/sh

那么问题来了,如果这个脚本是有参数的,如何传递参数呢?
下面这样是不行的
`curl -fsSL "http://somewhere/yourscript.sh" | /bin/sh "1"`
10721 次点击
所在节点    Linux
8 条回复
LazyZhu
2015-09-07 18:06:51 +08:00
在这问不如自己搜索, Let me search it for:
https://stackoverflow.com/questions/5735666/execute-bash-script-from-url
chzyer
2015-09-07 19:48:36 +08:00
echo 'echo "hello $1"' | bash -s "df"
Ansen
2015-09-07 20:11:20 +08:00
把 curl 放脚本里面 用$1 $2 … 传入
ryd994
2015-09-07 20:26:27 +08:00
environ
curl -fsSL "http://somewhere/yourscript.sh" | VAR=123 /bin/sh
另外,如果你对服务器有控制的话,也可以直接组合 get 参数。直接配置 web 服务器就行, nginx 都可以
qingxp9
2015-09-07 20:30:21 +08:00
rvm 的安装命令是
curl -sSL https://get.rvm.io | bash -s stable
聪明的你推理推理就出来了
结合 help 看一下
atom
2015-09-08 06:03:09 +08:00
@LazyZhu
不是伸手党,是关键词没有兄台组织得好哇,搜 curl AND bash 返回来太多干扰项,要么教我 curl 怎么玩,要么告诉我 getopt 怎么用 -__-
atom
2015-09-08 06:04:03 +08:00
@ryd994
偏门了,算是 work around 的方法,说明人很聪明 :D
atom
2015-09-08 06:04:46 +08:00
@qingxp9
有看 man ,但不认真

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/218912

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX