0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

the double-quoted delimiter still inhibits variable expansion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.