我想执行的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"