Skip to content
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

Pass multiple arguments into jq statement #607

Closed
rclod opened this issue Oct 28, 2014 · 4 comments
Closed

Pass multiple arguments into jq statement #607

rclod opened this issue Oct 28, 2014 · 4 comments
Labels

Comments

@rclod
Copy link

rclod commented Oct 28, 2014

Would like to be able to pass multiple arguments into a jq statement like so:

jq --arg ARG1 ${var1} ARG2 ${var2} '.$ARG1[$ARG2 | tonumber].width'

@pkoppstein
Copy link
Contributor

@rclod - You can pass in as many named arguments as you like by repeating the "--arg NAME VALUE" pattern.

@rclod
Copy link
Author

rclod commented Oct 28, 2014

thanks! I had tried that earlier, but had forgotten to put quotes around my variable call.

This ended up working as expected:

jq --arg ARG1 ${var1} --arg ARG2 ${var2} '."$ARG1"[$ARG2 | tonumber].width'

@rclod rclod closed this as completed Oct 28, 2014
@pkoppstein
Copy link
Contributor

@rclod - Because of variations between different versions of jq, it's sometimes simpler just to use the form .[s] instead of .s. Or in your case: .[$ARG1][$ARG2]

@rclod
Copy link
Author

rclod commented Oct 28, 2014

You're right, the quotes didn't end up working, but the brackets did.

jq --arg ARG1 ${var1} --arg ARG2 ${var2} '.[$ARG1][$ARG2 | tonumber].width'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants