Adobe
Adobe

Reputation: 13477

Test for both: boolean and string?

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?

Upvotes: 0

Views: 74

Answers (1)

choroba
choroba

Reputation: 241918

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

Upvotes: 1

Related Questions