I am trying to get url from the yml file. So if $NODES is null then return ENV variable URL or else the URL which is coming from yml file return that.
Here if is not working for me. If the condition is breaking. Also, local NODES variable value it prints null(when I did echo "$NODES"
)
My Code is something like this
SOURCE="$(dirname $0)/test.yml"
function query() {
cat "$SOURCE" | yq -r "$@"
}
function get_urls() {
local ENV="$1"
local NODES=$(query ".env[\"$ENV\"].urls")
if [ -z "$NODES" ];
then
echo $ENV_URL
else
query ".urls.$NODES[]" | paste -sd "," -
fi
}
Here if I change if [ -z "$NODES" ]
to if [ "$NODES" == "null"]
or if [ "$NODES" == null ]
Then script works.
But how to make it work using -z
?