2

I want an if statement in my bash script that does:

if [[ "$v" == "A" || my_func $x $y ]] ; then

but I get the error "conditional binary operator expected". I've tried putting quotes round the parameters in the call to my_func, but still no good. Tried playing around with eval, which didn't help either.

Thanks for any help.

2
  • [[ ]] is not part of if syntax; if takes a command, and [[ happens to be a builtin which can act as a comand, but not all things passed to if need to be within [[ ]] -- only tests and non-numeric comparisons (numeric comparisons should use (( ))). Commented Mar 13, 2012 at 14:30
  • I don't understand why you are using [[ instead of [ here. You can simply do: if [ "$v" = A ] || my_func $x $y; then ... or even 'test $v = A || my_func $x $y && ...' Commented Mar 13, 2012 at 14:57

1 Answer 1

7

You can try:

if [[ "$v" == "A" ]] || my_func $x $y ; 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.