Skip to content

Instantly share code, notes, and snippets.

@jhmt
Created March 3, 2023 19:46
Show Gist options
  • Save jhmt/e4ada765765041b6d15058097a312c2a to your computer and use it in GitHub Desktop.
Save jhmt/e4ada765765041b6d15058097a312c2a to your computer and use it in GitHub Desktop.
Pass parameter to a jq query in a shell script file.
#!/bin/bash
url="https://my.sample.com/5678"
objName=$(cat sample.json|jq --arg URL "$url" '[.[]|select(.owner.owner_url==$URL)][0]'|jq '.name')
echo $objName
[
{
"name": "abc",
"owner": {
"owner_url": "https://my.sample.com/1234"
}
},
{
"name": "def",
"owner": {
}
},
{
"name": "ghq",
"owner": {
"owner_url": "https://my.sample.com/5678"
}
},
{
"name": "zy",
"owner": {
"team": "my team"
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment