Variables are not expanded within single-quotes. Rewrite using double-quotes:
curl -X POST -H 'Content-type: application/json' --data "{\"text\": \"${message}\"}"
Just remember that double-quotes within double-quotes have to be escaped.
Another variation could be:
curl -X POST -H 'Content-type: application/json' --data '{"text": "'"${message}"'"}'
This one breaks out of the single quotes, encloses ${message}
within double-quotes to prevent word splitting, and then finishes with another single-quoted string. That is:
... '{"text": "'"${message}"'"}'
^^^^^^^^^^^^
single-quoted string
... '{"text": "'"${message}"'"}'
^^^^^^^^^^^^
double-quoted string
... '{"text": "'"${message}"'"}'
^^^^
single-quoted string
However, as the other answer and @Charles Duffy pointed out in a comment, this is not a robust solution, because literal "
and other characters in $message
may break the JSON.
Use the other solution, which passes the content of $message
to jq
in a safe way, and jq
takes care of correct escaping.