When I run the following script it keeps defaulting to the else statement and I'm not sure why. I have even included an echo $workflow which showed me the name that I was expecting to see but it still keeps defaulting to the else statement.
I've tried including an export namecheck=$workflow to see if that was the issue but it still gave the same end result
#!/bin/sh
read -p "Enter the workflow name: " workflowName
workflowName=${workflowName}
curl --request GET --url https://website.com > workflowjson.txt
workflow=$(jq -r .metadata.name workflowjson.txt)
echo $workflow
if [ -z "$workflow" ] then
echo "Workflow is Valid"
else
echo "Workflow is not valid"
fi
CodePudding user response:
man test
shows
-z STRING
the length ofSTRING
is zero
The code outputs Workflow is Valid
when the workflow is empty.
Switch the then
and else
parts, or negate the condition (use -n
instead of -z
).
CodePudding user response:
try taking the quotes out around workflow and put then in a separate line
if [ -z $workflow ]
then
echo "Workflow is Valid"
else
echo "Workflow is not valid"
fi