如何在Paranthes中使用EOF运行这个bash命令



我有这个curl命令:

curl -X POST "https://api.datadoghq.com/api/v1/synthetics/tests/trigger" 
-H "Content-Type: application/json" 
-H "DD-API-KEY: xxx" 
-H "DD-APPLICATION-KEY: yyy" 
-d @- << EOF
{
"tests": [
{
"public_id": "123-far-456"
}
]
}
EOF

我想在CCD_ 1内部运行,以将结果输入到变量中。像这样:

curl_response=$(curl -X POST "https://api.datadoghq.com/api/v1/synthetics/tests/trigger" 
-H "Content-Type: application/json" 
-H "DD-API-KEY: xxx" 
-H "DD-APPLICATION-KEY: yyy" 
-d @- << EOF
{
"tests": [
{
"public_id": "123-far-456"
}
]
}
EOF)

如何逃离EOF来运行此程序?我试过-d @- << datadog.json,但不起作用。

令牌EOF必须在自己的一行上,并且不能以任何空格开头:

curl_response=$(curl -X POST "https://api.datadoghq.com/api/v1/synthetics/tests/trigger" 
-H "Content-Type: application/json" 
-H "DD-API-KEY: xxx" 
-H "DD-APPLICATION-KEY: yyy" 
-d @- << EOF
{
"tests": [
{
"public_id": "123-far-456"
}
]
}
EOF
)

是的,很难看。如果你想要漂亮,不要使用bash;(

我尝试了-d @- << datadog.json,但不起作用。

从文件重定向时,请使用单个<。但在这种情况下,curl允许您简单地执行-d @datadog.json从文件中读取,而不需要任何shell魔术。

最新更新