I have a scenario where I am running the following code:
error_count=0
(cd tmp1 && terraform init -backend=false > /dev/null && terraform validate && echo "Terraform format check passed successfully in -------> xxx" && rm -rf .terraform*) || (echo "Terraform validation failed in xxx" && cd tmp && rm -rf .terraform* && let "error_count=error_count+1")
(cd tmp2 && terraform init -backend=false > /dev/null && terraform validate && echo "Terraform format check passed successfully in -------> yyy" && rm -rf .terraform) || (echo "Terraform validation failed in yyy" && cd tmp && rm -rf .terraform && let "error_count=error_count+1")
echo $error_count
if [ "$error_count" -gt 0 ]; then
echo "terraform check failed"
exit 1
else
echo "terraform check passed"
fi
What I observe here is even if the condition fails, the error_count=0
value remains the same. How can I increment the counter on a failing condition?