Donislav Belev
Donislav Belev

Reputation: 117

Curl payload breaks on whitespace

I need to do a curl POST request like that:

curl -X POST -H 'Content-type: application/json' --data $TEXT $URL

The TEXT variable I have defined like this:

TEXT="{\"text\":\"Some text $UUID\"}"

As you may note I want to send also a variable named UUID in the payload.

The issue I have is - if I send it like this the whitespaces inside \"text\":\"Some text $UUID\" break the curl and if I remove the whitespaces like \"text\":\"Some-text-$UUID\", it works right.

Upvotes: 0

Views: 1195

Answers (1)

user000001
user000001

Reputation: 33387

Variables in bash should be quoted, otherwise the value will be broken into tokens based on spaces, tabs, or other characters that happen to be in IFS, and then expanded as a glob if it contains * or ? etc.

Try with the below command:

curl -X POST -H 'Content-type: application/json' --data "$TEXT" "$URL"

Upvotes: 1

Related Questions