If else continue to check value until it it is right

i have script which get Input via READ value and compare it from file.
when found do some stuff...if not found again ask for Input until you dont enter Right value.

#!/bin/ksh
echo "SID must be in oratab file"
echo "Enter ORACLE_SID of Database:\c "
read ORACLE_SID
x=`cat /etc/oratab| grep $ORACLE_SID | wc -l`
for X in $x
do
        if [[ $X -eq 1 ]];then
                echo "SID FOUND"
        else
                echo "nothing found"
                echo "Enter valid SID"
                continue
        fi
done

but script just check value ,it does not continue keep ask or value , if value is not correct.

Could you please help on it.

Thanks.

That is a Useless Use of cat and Useless Use of wc -l

Use an infinite while loop and break when found:

#!/bin/ksh
echo "SID must be in oratab file"
echo "Enter ORACLE_SID of Database:\c "
read ORACLE_SID
while :
do
        if [[ $( grep -wc "$ORACLE_SID" /etc/oratab ) -ne 0 ]]
        then
                echo "SID Found"
                break;
        else
                echo "nothing found"
                echo "Enter valid SID"
                read ORACLE_SID
                continue;
        fi
done
1 Like

That's an odd if . Most likely you just want:

if grep -q "$ORACLE_SID" /etc/oratab

or

if grep "$ORACLE_SID" /etc/oratab >/dev/null 2>&1

edit: "Useless Use of Test" / "Useless Use of Backticks" @ bipinajith :wink:

1 Like

Thanks , i remember you ..you helped me last time .