【问题标题】:Is it possible to pass extra argument to perl or bash script when executing it via curl?通过 curl 执行 perl 或 bash 脚本时是否可以将额外的参数传递给它?
【发布时间】:2016-05-06 06:23:18
【问题描述】:

很确定这是一个普遍的问题,不仅与 perl 或 bash 有关,而且每当我从 Internet 卷曲一些受信任的 bash/perl 脚本时,我都会将其运行为:-

curl -L https://somesite.com/somescript | bash

它将运行托管在https://somesite.com/somescript 中的脚本。但是是否可以像文件名或目录名一样向该脚本传递额外的参数?

到目前为止,据我了解,https://somesite.com/somescript 的纯文本通过管道传输到 bash,bash 将在流式传输时执行somescript 的每一行,但我对如何将参数传递给正在运行的脚本有点迷茫.

【问题讨论】:

  • 使用 Perl 你可以做到:curl -L … | perl - <arguments>
  • 赞成为 perl 寻找解决方案。我不知道它存在。
  • (抱歉,错过了您要求提供perlbash。已恢复标签。)

标签: bash perl curl command-line


【解决方案1】:
  • bash

    curl -L https://somesite.com/somescript | bash -s arg1 arg2
    
    bash <( curl -L https://somesite.com/somescript ) arg1 arg2
    
  • perl:

    curl -L https://somesite.com/somescript | perl - arg1 arg2
    
    perl <( curl -L https://somesite.com/somescript ) arg1 arg2
    

【讨论】:

  • 优秀。这比@Biffen 评论的解决方案更通用。非常感谢。 :)
  • 嗯,我的印象是 - 或者 bash 中的 -- 表示不再解析参数,应该将其视为文字字符串。我不知道我在哪里看到的,但我似乎找不到它的链接。
  • curl ... | bash -s arg1 arg2
  • @shriek, -- 通常用于表示参数的结束。 - 通常用于表示需要文件名的标准输入或标准输出。 bash 不同:“- 的参数等价于 --。”
  • @chepner,谢谢!我知道有类似的东西,但我找不到。 (太盲目了。)添加答案。
猜你喜欢
  • 2011-06-06
  • 1970-01-01
  • 2015-07-12
  • 2021-11-18
  • 1970-01-01
  • 2013-03-30
  • 2014-12-25
  • 2019-02-08
  • 2014-10-04
相关资源
最近更新 更多