Created
March 3, 2023 19:46
-
-
Save jhmt/e4ada765765041b6d15058097a312c2a to your computer and use it in GitHub Desktop.
Pass parameter to a jq query in a shell script file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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