-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dump shell variables #789
Comments
This works for simple values $ jq -r 'to_entries | map("\(.key)=\(.value)") | .[]' example.json
duration=233
extractor=soundcloud
protocol=http
upload_date=20141111 This works for complex values jq -r 'to_entries | map("\(.key)=\(.value | @sh)") | .[]' This works to filter certain keys jq -r '{duration, protocol} | to_entries | map("\(.key)=\(.value | @sh)") | .[]' However, I am still interested if this can be done with simpler commands. |
It might be nice to add a |
I ended up creating a shell script called jq2sh that takes as input arguments the variable name and jq expression to generate shell variable definitions. Since you'll most likely consume the generated shell script from the shell itself, I thought it was more intuitive to create it as a handy command that can be called with the essential bit of jq. For example, the following invocation:
produces the following output:
for a JSON supplied as standard input:
This will typically be used in an |
I do something similar with a shell function I call |
Given this example file
I would like to dump these “variables” so that they can be used with a shell
script. Output would be like this
This command gets me close, but does not include the variable (key) names:
The text was updated successfully, but these errors were encountered: