0

I'd like to cheick that the one of two options are set: either the bin to true, or str is provided:

bin=false; str=; if $bin -o [ -n "$str" ]; then echo yes; fi

doesn't echoes anything, as it should be, but:

bin=false; str='str'; if $bin -o [ -n "$str" ]; then echo yes; fi

doesn't echo either - while it should. What do I do wrong?

1 Answer 1

1

Your -o option is getting passed to false. You need ||:

bin=false; str=; if $bin || [ -n "$str" ]; then echo yes; fi
bin=false; str='str'; if $bin || [ -n "$str" ]; then echo yes; fi
Sign up to request clarification or add additional context in comments.

3 Comments

@Adobe: The reason that -o isn't working is that it's not part of if syntax (it's not getting passed to false, but with false to if), but it's part of the syntax of test (aka [).
@DennisWilliamson: Set $bin to echo. You will see that -o is getting passed to $bin, whose result goes to if.
Thanks for pointing that out. I overlooked the fact that if executes its argument. However, the part I said about test is correct.

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.