卷曲 brace/bracket 有问题

Curl having issue with brace/bracket

我正在尝试在 .sh 文件中执行以下行:

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

它会给我一个像

这样的错误
curl: (3) [globbing] unmatched close brace/bracket in column 7

但是,当我 运行 命令没有像这样的 shell 变量时

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

它工作正常。

这是怎么回事。很纳闷。

感谢帮助

试试这个(转义双引号并改用 "$test2"

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