Is there a better way to pass string output from jq to bash? -


i’ve discovered jq , been loving it. 1 thing find myself doing lot though stuff like:

result=$(jq --raw-output '.some | .filters // ""') if [[ $result ]];     foo else     bar fi 

the default empty string seems play more nicely bash "truthiness" e.g. if [[ $result != "null" ]], , raw-output necessary store resultant string in variable. question is, i’m using these 2 tweaks consistently in scripts, there perhaps better way achieve same functionality? or make sense (as possible enhancement jq) able set couple env vars control behavior duration of script?

you can use -e flag make jq return exit code 0 if last output value neither false or null logic may become:

result=$(jq -e -r '.some | .filters') && foo || bar 

Comments

Popular posts from this blog

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - On Gitbash - Bower : ENOGIT git is not installed or not in the PATH -