Error reading two input variables

Hello all,

I've been out of programming for awhile so sorry about the stupid, elementary question.

I'm trying to read two inputs and compare them to a list entered as a parameter via the terminal. The script is

#!/bin/bash
read -p "Enter the numbers" NUM1 NUM2
for VALUE in $@; do
        if [ $VALUE -lt $NUM1 && $VALUE -gt $NUM2 ]; then COUNT=$((COUNT+1)); fi
done
echo There are $COUNT numbers in between.

I execute the script via:

./script5 5 10 6 12 5 18 10 4 19 21 5 12 18 22

and enter the values "6 10" upon the query. After the command is run, I am given this as the error:

./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'
./script5: line 4: [: missing `]'

What am I missing? A single quote somewhere?

Hi, try:

if [ $VALUE -lt $NUM1 ] && [ $VALUE -gt $NUM2 ] ... 

That works, but I now receive the error

Enter the numbers10 20
./script5: line 4: [5: command not found
./script5: line 4: [6: command not found
./script5: line 4: [5: command not found
./script5: line 4: [4: command not found
./script5: line 4: [5: command not found
There are numbers in between.

To get these errors, you must have omitted the space between [ and $VALUE . Please retry this using the EXACT spacing shown in Scrutinizer's suggestion.

Thank you! That seems to have fixed syntax issues.

You can also use

[ $VALUE -lt $NUM1 -a $VALUE -gt $NUM2 ]

Please note that you need to enter the larger number first if you want your test to succeed (which may not be what you desire) Also note that it is good practice to double quote variable expansions to be safe from surprises like embedded spaces (not applicable in this case of just numbers)

Note regarding the use of -a :

test: application usage