0

In BASH, I have an if statement like so:

if dokku ps:report $APP_NAME --deployed && ! dokku certs:report $APP_NAME --ssl-enabled; then echo "works"; fi

Each command outputs true or false. I want the then clause to get executed when the first command outputs true and the second outputs false (which is why I have the !). But when I run this, it outputs:

true
false

If I run the second command individually:

dokku certs:report $APP_NAME --ssl-enabled

It outputs false. So the negation in my original if statement isn't working. What am I doing wrong here?

1 Answer 1

2

Here's an easier way to reproduce your problem:

if echo false
then
  echo "Why does this print?"
fi

This is because the command output is irrelevant. if, && and || all look at the command's exit code. They don't try to interpret English text.

You can instead use string comparison:

if [ "$(dokku ps:report $APP_NAME --deployed)" = "true" ] && [ "$(dokku certs:report $APP_NAME --ssl-enabled)" = "false" ]
then ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.