我有下面的代码。
curl -X POST --data-urlencode 'payload={"channel": "#general", "username": "webhookbot", "text": "This is posted to #general and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx
这个命令发送This is posted to #general and comes from a bot named webhookbot
到Slack Channel
,现在我想用输出替换这个
wc -l ips.txt | awk '{print $1}'
我要这个 :
curl -X POST --data-urlencode 'payload={"channel": "#general", "username": "webhookbot", "text": "OUTPUT OF wc -l command , like number 154", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx
我该怎么做 ?
答案1
curl -X POST --data-urlencode "payload={'channel': '#general', 'username': 'webhookbot', 'text': \"$(wc -l ips.txt | awk '{print $1}')\", 'icon_emoji': ':ghost:'}" https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx
答案2
您应该能够使用反引号进行命令扩展:
curl -X POST --data-urlencode 'payload={"channel": "#general", "username": "webhookbot", "text": "`wc -l ips.txt | awk '{print $1}'`", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx