I have a bash script:
#! /bin/bash
someId=$(curl -sk -H -X POST -d "fizzbuzz" "https://someapi.example.com/v1/orders/fire" | jq '.someId')
if [ -z "$someId" ]; then
echo "Order Placement failed; unable to parse someId from the response"
exit 1
fi
echo "...order $someId placed"
When I run this I get the following output:
...order null placed
So somehow $someId is null but then...shouldn't I be seeing the "Order Placement failed; unable to parse someId from the response" echo instead?
How can I modify the if [ -z "$someId" ]; then conditional to execute if $someId is null?
-zchecks only for zero-length strings.[ -z "$someId" ] || [ "$someId" = null ](splitting it into two separate tests that way complies with current POSIX guidelines; see the OB markers in pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html, flagging other ways to combine tests as obsolescent).