Compare array value with user input bash

I'm trying to compare user input with a string array value, when I do so both values seem to be the same when I print them out but the if statement doesn't see them as equal. Is there something obvious I'm missing.

k=0
while [ -z $arg1 ]
do
    while [ $k -ne 9 ]
    do
    # ask question
    echo "${question[k]}"
    answer="${answer[k]}"
    read -p "YES/NO " arg1
    # check answer
    if [ '$arg1' = '$answer' ]; # problem is here
    then
        echo "Correct!"
        let "k=$k+1"
    else
        echo "Incorrect!"
        echo "Your answer: $arg1"
        echo "Correct answer: $answer"
    fi
    done
done

Answers


Replace: You have not put what is in answer and question array

 if [ '$arg1' = '$answer' ];
 with
 if [ "$arg1" = "$answer" ] ; 

and check


Need Your Help

Check Session variable and Redirect to login page before page load

c# asp.net redirect page-lifecycle page-init

How can I check a variable and redirect to another page before the page loads using ASP.NET?