Reputation: 3
I'm trying to use curl
command to perform a POST request. The format of the content is the message I am POSTing is JSON. In the example below, I don’t get how to add the $*
part, which should be all parameters you add when you start the .sh
file.
curl -X POST --data-urlencode 'payload={"channel": "#serverstatus", "username": "BananaStatus", "text": "${*}", "icon_emoji": ":banana:"}' https://hooks.slack.com/services/
When I run that, I just receive the ${*}
as text.
Upvotes: 0
Views: 41
Reputation: 370
When using variables in the middle of strings you should use double quotes.
So, use:
"payload={\"channel\": \"#serverstatus\", \"username\": \"BananaStatus\", \"text\": \"${*}\", \"icon_emoji\": \":banana:\"}"
Instead of:
'payload={"channel": "#serverstatus", "username": "BananaStatus", "text": "${*}", "icon_emoji": ":banana:"}'
Upvotes: 1
Reputation: 69
bash don't expand variables between ' ' (single quotes)
you have to use double quote (" ")
try:
'...any text..'"${*}"'...other text..'
it gives whith your example:
curl -X POST --data-urlencode 'payload={"channel": "#serverstatus", "username": "BananaStatus", "text": "'"${*}"'", "icon_emoji": ":banana:"}' https://hooks.slack.com/services/
Upvotes: 2