Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass a variable containing a JSON as a parameter of a function by command line

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{"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'}'

>Solution :

You need to use Shell Parameter Expansion to access variables:

omv-rpc -u admin 'ShareMgmt' 'set' "${JSON_STRING}"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading