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.