jeudi 13 juillet 2017

condition evaluating to "TRUE"

I am trying to check for duplicate records in my database using shell scripting. For this, I have created a function named "check()" which echo's True or False and is stored in variable "result". But while evaluating using if statement it is always returning "True".

#redundancy check function
check() {
    temp=$(grep -w -c "$1" database.dat)
    echo $temp
    if [ "$temp" != 0 ]
        then
            echo True
        else
            echo False
    fi
}

insert() {
    option="y"
    while [ "$option" == "y" ]
    do
        echo "Rollno: \c"
        read roll
        result="$(check $roll)"
        echo $result
        if [ "$result" == "False" ]
            then        
                echo Do something
            else
                echo "ERROR: Duplicate record found...\nEXITING...\n"
                option="n"
        fi
    done
}

Aucun commentaire:

Enregistrer un commentaire