0

Can anybody tell me what is wrong with this syntax:

if [ "$1" == "postfix" || "$1" == "all" ]; then
    echo test
fi
1
  • 1
    [ a == b ] || [ c == d ] or [ a == b -o c == d ]. Or [[ ... ]] instead. Commented Dec 3, 2014 at 23:56

2 Answers 2

2

Use either

if [ "$1" = "postfix" ] || [ "$1" = "all" ]; then

or

if [ "$1" = "postfix" -o "$1" = "all" ]; then

|| combines two commands (and the [ is a command). Within the [ ... ] the operator -o is used for or.

Another way to use || is to use it inside [[ instead of [.

In any way, the correct operator for equality is = inside [ ... ] as it is the POSIX standard (according to man bash). == is supported, though.

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to do this, use [[ test form :

if [[ $1 == "postfix" || $1 == "all" ]; then

[[ is a bash keyword similar to (but more powerful than) the [ command. See http://mywiki.wooledge.org/BashFAQ/031 and http://mywiki.wooledge.org/BashGuide/TestsAndConditionals Unless you're writing for POSIX sh, we recommend [[

or

if [ "$1" == "postfix" ] || [ "$1" == "all" ]; then

1 Comment

There's not much difference to my answer, so ⁺¹ from me ;-)

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.