通过命令行传递包含 JSON 的变量作为函数的参数
我需要在需要 Openmediavault 命令的 JSON 中输入一个值。有问题的命令是这样的:
omv-rpc -u admin 'ShareMgmt' 'set' '{"name":"120GB","mntentref":"71fdbd90-ce16-4726-ad8d-35ba8664b4c6","reldirpath": "/","mode": "775","comment": "","uuid": "fa4b1c66-ef79-11e5-87a0-0002b3a176b4"}'
但是我需要引入另一个我保存在变量中的 JSON 。我已经这样安装了它:
JSON_STRING=$( jq -n \
--arg referencia "$code_val" \
'{name:"120GB",mntentref:$referencia ,reldirpath: "/",mode: "775",comment: "",uuid: "fa4b1c66-ef79-11e5-87a0-0002b3a176b4"}')
退出echo $JSON_STRING:
{"name":"120GB","mntentref":"71fdbd90-ce16-4726-ad8d-35ba8664b4c6","reldirpath": "/","mode": "775","comment": "","uuid": "fa4b1c66-ef79-11e5-87a0-0002b3a176b4"}
现在我想构建第一个函数并发送我通过参数创建的JSON,但我不会知道怎么做,你能帮我一下吗?
我尝试了这种方法,但它给出了错误。我对 Debian 控制台命令知之甚少:
omv-rpc -u admin 'ShareMgmt' 'set' '{'echo $JSON_STRING'}'
I need to enter a value in a JSON that requires an Openmediavault command. The command in question is this:
omv-rpc -u admin 'ShareMgmt' 'set' '{"name":"120GB","mntentref":"71fdbd90-ce16-4726-ad8d-35ba8664b4c6","reldirpath": "/","mode": "775","comment": "","uuid": "fa4b1c66-ef79-11e5-87a0-0002b3a176b4"}'
But I need to introduce another JSON that I have saved in a variable. I have mounted it like this:
JSON_STRING=$( jq -n \
--arg referencia "$code_val" \
'{name:"120GB",mntentref:$referencia ,reldirpath: "/",mode: "775",comment: "",uuid: "fa4b1c66-ef79-11e5-87a0-0002b3a176b4"}')
The exit echo $JSON_STRING:
{"name":"120GB","mntentref":"71fdbd90-ce16-4726-ad8d-35ba8664b4c6","reldirpath": "/","mode": "775","comment": "","uuid": "fa4b1c66-ef79-11e5-87a0-0002b3a176b4"}
Now I want to build the first function and send the JSON that I have created by parameters, but I would not know how to do it, can you give me a hand?
I tried this way but it gives error. I have little knowledge of Debian console commands:
omv-rpc -u admin 'ShareMgmt' 'set' '{'echo $JSON_STRING'}'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 Shell 参数扩展< /a> 访问变量:
You need to use Shell Parameter Expansion to access variables: