Created
November 6, 2018 03:20
-
-
Save abner/7ac67c289fa86d716e32f4ed338de30a to your computer and use it in GitHub Desktop.
jq search id
This file contains 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 | |
JQ_CMD="$PWD/jq" | |
if [ ! -f $JQ_CMD ]; then | |
echo "Downloading jq binary..." \ | |
&& wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -O $JQ_CMD \ | |
&& chmod +x $JQ_CMD \ | |
&& echo "JQ was downloaded" | |
fi | |
read -r -d '' JSON << EOM | |
{ | |
"entities": [ | |
{ | |
"id": "1", | |
"identifier": "module1" | |
}, | |
{ | |
"id": "2", | |
"identifier": "module2" | |
} | |
] | |
} | |
EOM | |
echo $JSON | |
moduleName="module1" | |
#moduleName="module2" | |
#moduleId=$(echo $JSON | $JQ_CMD -r --arg MODULE_NAME "$moduleName" '.entities[] | select(.identifier==$MODULE_NAME)|.id') | |
moduleId=$(echo $JSON | MODULE_NAME=$moduleName $JQ_CMD -r '.entities[] | select(.identifier==env.MODULE_NAME)|.id') | |
echo "MODULE ID ----> $moduleId" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment