I wanted to check if the value of variable is empty in an if statement and take action based on the result from the same in a Bash script.
I am doing something like this:
if [ -z "${OriginSlotName-}" ] && [ -z "${TargetSlotName-}" ]; then
echo "Value of both the slot are not given";
Although I pass the argument OriginSlotName and TargetSlotName as empty, this particular iteration is not executed rather it goes to the part of the bash script where its expecting both OriginSlotName and TargetSlotName.
Does anyone know, what might be wrong here? Or is there a better way to structure the script? As of now I have an if statement with four branches. The if statement looks something like the following:
If (OriginSlotName & OriginSlotName != Empty)
Do something
else if (OriginSlotName = Empty & OriginSlotName != Empty )
Do something
else if (OriginSlotName != Empty & OriginSlotName = Empty )
Do something
else
Do something (Both OriginSlotName & OriginSlotName = Empty )
Is there a better and more efficient way to perform these checks and take relevant action based on the result, apart from using if?