简体   繁体   中英

Curl having issue with brace/bracket

I am trying to execute the following line in .sh file:

test2='{"admins":{"names":["superuser"],"roles":["admins", "test"]}}'
curl $url -X PUT -H 'content-type: application/json' -H 'accept: application/json' -d $test2

it would give me an error like

curl: (3) [globbing] unmatched close brace/bracket in column 7

However, when I run the command without a shell variable like this

curl $url -X PUT -H 'content-type: application/json' -H 'accept: application/json' -d '{"admins":{"names":["superuser"],"roles":["admins", "test"]}}'

it works fine.

What is going on here. Very puzzled.

Thanks for the help

Try this (Escaping double quotes and using "$test2" instead)

test2="{\"admins\":{\"names\":[\"superuser\"],\"roles\":[\"admins\", \"test\"]}}"
curl $url -X PUT -H 'content-type: application/json' -H 'accept: application/json' -d "$test2"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM