在下面的例子中(我是从PagerDuty网页获得的):
machine="hi"
curl -H "Content-type: application/json" -X POST \
-d "{ \"service_key\": \"e93facc04764012d7bfb002500d5d1a6\", \"description\": \"FAILURE for production/HTTP on machine $machine\" }" \
"https://events.pagerduty.com/generic/2010-04-15/create_event.json"
我想在描述中使用变量,如:
"description": "FAILURE for $machine",
然而它不起作用,它只显示"FAILURE for $machine",
我试过"FAILURE for ${machine}",
,但它也不起作用。你知道怎么解决吗?
答案 0 :(得分:2)
问题是使用单引号。你需要在字符串中使用双引号和转义和双引号:
curl -H "Content-type: application/json" -X POST \
-d "{
\"service_key\": \"e93facc04764012d7bfb002500d5d1a6\",
...
\"description\": \"FAILURE for production/HTTP on machine $machine\"
}" \
"https://events.pagerduty.com/generic/2010-04-15/create_event.json"
相当乏味,但它会完成这项工作。