首页 > Web开发 > 详细

curl方式执行脚本时传参问题

时间:2017-07-25 15:22:27      阅读:230      评论:0      收藏:0      [点我收藏+]

参考:

https://stackoverflow.com/questions/4642915/passing-parameters-to-bash-when-executing-a-script-fetched-by-curl/4642975


通常执行发布机上的脚本时习惯使用以下方式:

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


若涉及到传入参数时,则可使用

1. curl http://example.com/script.sh | bash -s arg1 arg2
2. curl http://example.com/script.sh | bash /dev/stdin arg1 arg2
3. bash <( curl http://example.com/script.sh ) arg1


若参数中带有"-",则可使用长选项"--"解决

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

若参数为"-p blah -d blah",则可使用以下命令执行

curl http://example.com/script.sh | bash -s -- -p blah -d blah


不止是curl的输入,其他方式的输入也满足。可以通过以下例子深入理解下

echo ‘i=1; for a in $@; do echo "$i = $a"; i=$((i+1)); done‘ | bash -s -- -a1 -a2 -a3 --long some_text


curl方式执行脚本时传参问题

原文:http://xoyabc.blog.51cto.com/7401264/1950743

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!