0

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.

2 Answers 2

2

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/  
Sign up to request clarification or add additional context in comments.

Comments

1

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:"}'

Comments

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.