When I try with this baby example:
$ a=$(echo '{"error": "not_found"}' | jq .error)
I get:
$ declare -p a
declare -- a="\"not_found\""
So the quotes are also in the output of jq. So you need this:
if [[ $existed_design_document = "\"not_found\"" ]]
As @EtanReisner points out (thanks!): jq has the -r flag:
With this option, if the filter´s result is a string then it will
be written directly to standard output rather than being formatted
as a JSON string with quotes. This can be useful for making jq fil‐
ters talk to non-JSON-based systems.
So you should even do this:
existed_design_document=$(curl "Administrator:*******@couchbase:8092/$MY_APP_DB_BUCKET/_design/dev_$environment" | jq -r .error)
echo "$existed_design_document"
if [[ $existed_design_document = "not_found" ]; then
echo "The document design does not exist"
fi
declare -p existed_design_documentorprintf '%q\n' "$existed_design_document"? Like so you'll see if there are funny characters in your variable.echois not reliable for this kind of inspections.bashallows==inside[...], but it's good to get in the habit of using=instead (or use[[ ... == ... ]]).