# Binary operator expected

**URL:** <https://community.unix.com/t/binary-operator-expected/365944>\
**Category:** UNIX for Beginners Q & A\
**Created:** [April 4, 2017, 6:06am UTC](https://community.unix.com/t/binary-operator-expected/365944 "2017-04-04T06:06:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SelvaKumarq](https://community.unix.com/letter_avatar/selvakumarq/32/6_22734026db12803ebb3e059622ac3534.png) [@SelvaKumarq](https://community.unix.com/u/SelvaKumarq)\
**Post date:** [April 4, 2017, 6:06am UTC](https://community.unix.com/t/binary-operator-expected/365944/1 "2017-04-04T06:06:13Z")

</div>

Hi Team,

I just started to learn shell scripting and i got this script from an online book and tried to run in my terminal. But it throws error message.

```nohighlight
echo $0
-bash

echo $UID
501

cat check_rootuser.sh
#!/bin/bash
# Run as root, of course.
LOG_DIR=/var/log
ROOT_UID=0 # Only users with $UID 0 have root privileges.
LINES=20 # Default number of lines saved.
E_XCD=66 # Can't change directory?
E_NOTROOT=67 # Nonroot exit error.

if ["$UID" ne "$ROOT_UID"]
then
echo "Must be root to run this script"
exit $E_NOTROOT
fi

```

```nohighlight
./check_rootuser.sh
./check_rootuser.sh: line 10: [: ne: binary operator expected

```

please help me to solve this error.

Thanks  
Selva

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_22734026db12803ebb3e059622ac3534.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [April 4, 2017, 7:10am UTC](https://community.unix.com/t/binary-operator-expected/365944/2 "2017-04-04T07:10:55Z")

</div>

Please share your `bash` version.

While the construct works well with `GNU bash, version 4.1.11(1)-release (amd64-portbld-freebsd9.0)` :

```nohighlight
if ["$UID" -ne "$ROOTUID"]; then echo "Must be root to run this script"; fi
Must be root to run this script

```

, it doesn't with `GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)` :

```nohighlight
if ["$UID" ne "$ROOTUID"]; then echo "Must be root to run this script"; fi
bash: [: ne: binary operator expected

```

Looks like a flaw in that `bash` version...

---

<div class="post-metadata">

**Author:** ![drysdalk](https://community.unix.com/letter_avatar/drysdalk/32/6_22734026db12803ebb3e059622ac3534.png) [@drysdalk](https://community.unix.com/u/drysdalk)\
**Post date:** [April 4, 2017, 8:23am UTC](https://community.unix.com/t/binary-operator-expected/365944/3 "2017-04-04T08:23:32Z")

</div>

Hi,

One thing you could try is using `!=` instead of `-ne` . As RudiC has said, different versions of Bash can behave differently in this type of situation, depending on what they think they're comparing and what the situation precisely is.

---

<div class="post-metadata">

**Author:** ![SelvaKumarq](https://community.unix.com/letter_avatar/selvakumarq/32/6_22734026db12803ebb3e059622ac3534.png) [@SelvaKumarq](https://community.unix.com/u/SelvaKumarq)\
**Post date:** [April 4, 2017, 9:47am UTC](https://community.unix.com/t/binary-operator-expected/365944/4 "2017-04-04T09:47:16Z")

</div>

bash --version  
GNU bash, version 4.1.2(1)-release (x86\_64-redhat-linux-gnu)

it looks like, it won't work in GNU bash, version 4.1.2(1)-release (x86\_64-redhat-linux-gnu)

---

<div class="post-metadata">

**Author:** ![drl](https://community.unix.com/user_avatar/community.unix.com/drl/32/542_2.png) [@drl](https://community.unix.com/u/drl)\
**Post date:** [April 4, 2017, 10:08am UTC](https://community.unix.com/t/binary-operator-expected/365944/5 "2017-04-04T10:08:25Z")

</div>

Hi.

When I looked at your script with `cat -A` , the `if` showed up as:

```nohighlight
if ["$UID" ?ne "$ROOT_UID"]$

```

which suggests that the minus sign is not the ASCII code `45 2D -`

Try changing that to a minus sign (on my keyboards, the key to the right of 0 [zero] ).

Did you edit this on Windows or some other non-Linux place?

Best wishes ... cheers, drl
