How do I send a curl request whose body contains a variables embedded in string?

 - run:
          name: notify on slack channel
          command: |
           sudo apt-get install curl |
           curl -X POST -H 'Content-type: application/json' \
            --data '{"text":"${ECS_SERVICE_NAME} deployed to staging with revision ${CIRCLE_SHA1}"}' \

ECS_SERVICE_NAME and CIRCLE_SHA1 are variables defined.
But when I run this I get it literally and not the values.

What’s the correct way to achieve this?

Hi @sudipbhandari126,

It looks like you curl request is using single quotes for the parameter.

In bash single quotes are used to preserve the literal value of each character inside the string. To fix this, change the single quotes to double quotes, and escape the double quotes inside the string, like in the example below.

You can find more information on quoting characters in bash here:

--data "{\"text\":{\"${ECS_SERVICE_NAME} deployed to staging with revision ${CIRCLE_SHA}\"}}"

Thanks a lot. It worked!!

I think it’s time to really learn some bash :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.