I'm trying to get the value of a resource in azure via AZ CLI, and pass that value to a variable in bash.
id=$(az synapse workspace show -n $name -g $rsname --query 'identity.principalId' -o tsv 2<&1)
if [[ $id == *"Not Found"* ]];
then
echo "Workspace already deleted."
fi
If the resource is not there, I am redirecting the output to the variable with 2<&1 so I can deal with it in the if-then conditional. $id is getting assigned the output correctly, but AZ CLI is still exiting the script with error "not found".
Is there anyway to keep it from exiting?