Awk

我想將輸出替換為文本

  • March 3, 2017

我有以下程式碼。

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 webhookbotSlack 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

我該怎麼做 ?

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

您應該能夠使用反引號進行命令擴展:

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

引用自:https://unix.stackexchange.com/questions/348931