# cannot properly employ "or" operator in an if statement (bash)

**URL:** <https://community.unix.com/t/cannot-properly-employ-or-operator-in-an-if-statement-bash/271377>\
**Category:** Shell Programming and Scripting\
**Created:** [August 12, 2010, 5:44pm UTC](https://community.unix.com/t/cannot-properly-employ-or-operator-in-an-if-statement-bash/271377 "2010-08-12T17:44:53Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![agama](https://community.unix.com/user_avatar/community.unix.com/agama/32/21613_2.png) [@agama](https://community.unix.com/u/agama)\
**Post date:** [August 12, 2010, 10:50pm UTC](https://community.unix.com/t/cannot-properly-employ-or-operator-in-an-if-statement-bash/271377/5 "2010-08-12T22:50:27Z")

</div>

Your original if statement was nearly correct. There must be a complete expression on either side of the or:

```nohighlight
if [[$sername == *DIFF*FA* || $sername == *DTI*FA*]]

```

Your second attempt isn't working because

```nohighlight
[expression]

```

is very much different than

```nohighlight
[[expression]]

```

The double bracket expression is interpreted by the shell and the right hand side is treated as a pattern (if not quoted). Single brackets are treated just like any any other command (remember that [ is a link to the test command). If wildcards (\* and ?) are used inside of single brackets, they are expanded as file names in the current directory and NOT treated as patterns. The filename expansion is then passed to the test command.

In my opinion it is best to avoid using single brackets in if and while statements in Kshell and bash. Forking to the test command is very inefficient not to mention the enhancements to the expressions that Kshell and bash provide.

---

_[View the full topic](https://community.unix.com/t/cannot-properly-employ-or-operator-in-an-if-statement-bash/271377)._
