V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
atom
V2EX  ›  Linux

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

  •  
  •   atom · 2015-09-07 17:55:57 +08:00 · 10703 次点击
    这是一个创建于 3151 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如果某个脚本托管在服务器上,大家一般会酷炫地直接用管道方式来下载并执行脚本

    $ 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"

    8 条回复    2015-09-08 06:04:46 +08:00
    LazyZhu
        1
    LazyZhu  
       2015-09-07 18:06:51 +08:00   ❤️ 1
    在这问不如自己搜索, Let me search it for:
    https://stackoverflow.com/questions/5735666/execute-bash-script-from-url
    chzyer
        2
    chzyer  
       2015-09-07 19:48:36 +08:00   ❤️ 1
    echo 'echo "hello $1"' | bash -s "df"
    Ansen
        3
    Ansen  
       2015-09-07 20:11:20 +08:00 via iPhone
    把 curl 放脚本里面 用$1 $2 … 传入
    ryd994
        4
    ryd994  
       2015-09-07 20:26:27 +08:00 via Android
    environ
    curl -fsSL "http://somewhere/yourscript.sh" | VAR=123 /bin/sh
    另外,如果你对服务器有控制的话,也可以直接组合 get 参数。直接配置 web 服务器就行, nginx 都可以
    qingxp9
        5
    qingxp9  
       2015-09-07 20:30:21 +08:00   ❤️ 1
    rvm 的安装命令是
    curl -sSL https://get.rvm.io | bash -s stable
    聪明的你推理推理就出来了
    结合 help 看一下
    atom
        6
    atom  
    OP
       2015-09-08 06:03:09 +08:00
    @LazyZhu
    不是伸手党,是关键词没有兄台组织得好哇,搜 curl AND bash 返回来太多干扰项,要么教我 curl 怎么玩,要么告诉我 getopt 怎么用 -__-
    atom
        7
    atom  
    OP
       2015-09-08 06:04:03 +08:00
    @ryd994
    偏门了,算是 work around 的方法,说明人很聪明 :D
    atom
        8
    atom  
    OP
       2015-09-08 06:04:46 +08:00
    @qingxp9
    有看 man ,但不认真
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1292 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:47 · PVG 01:47 · LAX 10:47 · JFK 13:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.