如何将命令输出传递给curl

时间:2017-03-08 18:40:28

标签: curl pipe

我使用curl将一些urlencoded内容发布到URL,我希望curl命令的内容来自管道。基本上...

... | curl -s --data-urlencode '{\"text\":\"$PIPE_RESULT\"}' http://...

我认为0美元可能会有效,但我收到了一个带有以下简单文字的invalid_payload错误:

echo "http://www.example.com" | curl -s --data-urlencode '{"text\":\"$0\"}' https:/...

1 个答案:

答案 0 :(得分:1)

xpgs救援!

echo "http://www.example.com" | \
xargs -I moo curl -s --data-urlencode '{"text\":\"moo\"}' https://example.com

' moo'给予xargs的字符串意味着它将取代“moo'在以下字符串中包含从stdin读取的内容。