[英]Variable insertion in a json sent by curl to the Discord api. "unmatched close brace/bracket in URL position X"
在向 Discord 发送 curl 请求时,我遇到了一个小问题。
我的脚本:
#!/bin/bash
discord_webhook="https://discord.com/api/webhooks/ID/XXXXX"
tmp_file=/tmp/toblock.tmp
blocked_ip=$(paste -s -d ' ' $tmp_file)
if ! [ -z "$discord_webhook" ]; then
curl -H "Content-Type: application/json" -d '{"username": "IP blocking", "embeds":[{"title":"New IP(s) blocked","description":"'$blocked_ip'"}]}' "$discord_webhook"
fi
/tmp/toblock.tmp 的内容是以下两行(测试随机 ip):
15.15.15.15
16.16.16.16
错误是
root@vm1 ~ # bash ad.sh
curl: (3) unmatched close brace/bracket in URL position 13:
16.16.16.16"}]}
^
有人会在我的 Curl 请求中看到错误在哪里吗?
$blocked_ip
包含空格,因此将 JSON 拆分为多个 arguments。 您需要将其放在双引号中以防止这种情况。
curl -H "Content-Type: application/json" -d '{"username": "IP blocking", "embeds":[{"title":"New IP(s) blocked","description":"'"$blocked_ip"'"}]}' "$discord_webhook"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.