Reputation: 23187
I need to interpolate curl body with variables into a shell script:
This is the script snippet:
curl -k \
-X PUT \
-d @- \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
"$SERVER_URL/api/v1/namespaces/$NAMESPACE/secrets/$SECRET_ID" <<-'EOF'
{
"kind": "Secret",
"apiVersion": "v1",
"metadata": {
"name": "$SECRET_ID"
},
"stringData": {
"$key": "$value"
}
}
EOF
However, neither $SECRET_ID
nor $key
nor $value
aure "resolved".
EDIT
I've tried that:
curl -k \
-X PUT \
-d @- \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
"$SERVER_URL/api/v1/namespaces/$NAMESPACE/secrets/$SECRET_ID" <<-"EOF"
{
"kind": "Secret",
"apiVersion": "v1",
"metadata": {
"name": "$SECRET_ID"
},
"stringData": {
"$key": "$value"
}
}
EOF
But it doesn't works.
Upvotes: 0
Views: 56
Reputation: 198294
You quoted your JSON in heredoc with <<-'EOF'
. If the heredoc delimiter is quoted, it will not expand variables. Use <<-EOF
to get the normal double-quoted variable-expansiony semantics.
Upvotes: 2