G
G
gleendo2018-12-11 21:36:17
bash
gleendo, 2018-12-11 21:36:17

How to compare 2 numbers entered by the user?

Tell me how to compare 2 numbers entered by the user from the keyboard?
In this case, it does not work correctly. Please tell me how to correct the comparison.

./main.sh: line 10: [: -eq: unary operator expected

number=10
count=5


for i in `seq 1 $count`; do
    echo "Input value: "
    
    read $value

    if [ $value -eq $number ] 
    then
       echo "Win!!!"

       exit
    fi
done

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2018-12-11
@jcmvbkbc

read $value

read valuesame, the name of the variable should be there.

S
Softer, 2018-12-11
@Softer

if ; then

B
bova, 2018-12-12
@bova8

something like that probably

#!/bin/bash
number=10
count=5
for i in `seq 1 $count`; do
    ok=0
    while [ $ok -eq 0 ]; do
        echo "Input value: "
        read value
        if [ `expr $value + 1 2> /dev/null` ] ; then
            ok=1
        fi
    done

    if [ $value -eq $number ]
    then
       echo "Win!!!"
       exit
    fi
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question