# :integer expression expected

**URL:** <https://community.unix.com/t/integer-expression-expected/275696>\
**Category:** Shell Programming and Scripting\
**Created:** [October 20, 2010, 9:41am UTC](https://community.unix.com/t/integer-expression-expected/275696 "2010-10-20T09:41:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![milink](https://community.unix.com/letter_avatar/milink/32/6_22734026db12803ebb3e059622ac3534.png) [@milink](https://community.unix.com/u/milink)\
**Post date:** [October 20, 2010, 9:41am UTC](https://community.unix.com/t/integer-expression-expected/275696/1 "2010-10-20T09:41:56Z")

</div>

Hi,

```nohighlight
echo $i

until ["$NUM" -gt "0"] || ["$NUM" -le "$i"]
do
read NUM
      if ["$NUM" -lt "1"] && ["$NUM" -gt "$i"] ; then
      printf "$FBOLD\nInvalid number, please enter valid backup number: $FREG"
      fi
done

```

Getting below error :

./import\_location.sh: line 234: [: : integer expression expected  
./import\_location.sh: line 234: [: : integer expression expected  
./import\_location.sh: line 237: [: : integer expression expected  
./import\_location.sh: line 234: [: : integer expression expected  
./import\_location.sh: line 234: [: : integer expression expected

where mistake is done ?

With Regards

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [October 20, 2010, 9:57am UTC](https://community.unix.com/t/integer-expression-expected/275696/2 "2010-10-20T09:57:47Z")

</div>

What value doesn $NUM have?

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [October 20, 2010, 9:58am UTC](https://community.unix.com/t/integer-expression-expected/275696/3 "2010-10-20T09:58:10Z")

</div>

As the error says, it is expecting at

```nohighlight
... [ "$NUM" ...

```

an integer.

Maybe echo $NUM to check what it currently is or add a set -x and a set +x to enable and disable debugging.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_22734026db12803ebb3e059622ac3534.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [October 20, 2010, 12:37pm UTC](https://community.unix.com/t/integer-expression-expected/275696/4 "2010-10-20T12:37:00Z")

</div>

What Shell are you using?  
What is a sample value for $i , and what does it signify?  
What is a sample value for $NUM?  
What is a valid range for $NUM ?

---

<div class="post-metadata">

**Author:** ![ctsgnb](https://community.unix.com/letter_avatar/ctsgnb/32/6_22734026db12803ebb3e059622ac3534.png) [@ctsgnb](https://community.unix.com/u/ctsgnb)\
**Post date:** [October 20, 2010, 12:45pm UTC](https://community.unix.com/t/integer-expression-expected/275696/5 "2010-10-20T12:45:57Z")

</div>

Which shell are you using ?  
try to  
double the bracket [[]]  
initialize your variable  
gather the contitions into one bracket [[||]] instead of [[]] || [[]]  
remove the double quote inside condition brackets (should be the last thing to try)  
... and see if a miracle happen 🙂

what about this statement :

```nohighlight
printf "$FBOLD\nInvalid number, please enter valid backup number: $FREG"

```

shouldn't it be smthg like

```nohighlight
printf "%s \nInvalid number, please enter valid backup number: " $FBOLD 
read FREG 

```

or whatever format should $FBOLD fit

I think your printf syntax may need to be checked

---

<div class="post-metadata">

**Author:** ![Chubler\_XL](https://community.unix.com/user_avatar/community.unix.com/chubler_xl/32/2077_2.png) [@Chubler\_XL](https://community.unix.com/u/Chubler_XL)\
**Post date:** [October 20, 2010, 2:26pm UTC](https://community.unix.com/t/integer-expression-expected/275696/6 "2010-10-20T14:26:22Z")

</div>

Try this:

```nohighlight
echo $i

while true
do
    read NUM
    if [$NUM -gt 0 -a $NUM -le $i] 2> /dev/null; then
        break
    fi
    printf "$FBOLD\nInvalid number, please enter valid backup number: $FREG"
done

```

Also handles any non numeric NUM values: test will fail so break isn't executed, redirect stderr to /dev/null to hide shell error message.
