I'm trying to write a simple bash script that will pipeline a jq
change of key-value, setting the value
for key to a new one I pass into my bash script.
I already got down the pipeline for changing the value, I run jq '.key = "newVal"'<config.json | sponge config.json
and this works for changing all the values I want, except I want to automate it so that I can just pass values I want changed into bash script and then have those replaced where newVal
is in my code above.
My attempt was this:
confMizerFinal(){ status=$1; minPath=$2; minOps=$3; jq '.status = "'$status''<config.json | sponge config.json; cat config.json; }
(I included just one jq pipeline to make it easier to read, of course I would be having one for each newVal1... I want to set. The issue is actually passing it into the value, in this case, neither '$status'
nor "$status"
, unfortunately. Am I maybe oversimplifying this, and I cannot just pass the positional param value to the .key in JSON?
All help is much appreciated, this site has been instrumental to advancing my knowledge in bash.