function terminating if i give input as space or no input and enter

HI
i have written a script to ask input from the user.
this script should promote the user for y/n input. if user enters anyother input then y/n
the script promotes him again. this below code is working fine for all the cases.

except for space and enter " if i give space and enter it is printing

echo "\n Goodbye ... !!!"

while [  ${confirm} != 'y' -a ${confirm} != 'Y'  ]
do
echo "\n Do you want to continue ? (y/n)"
read confirm # reads the option and proceedsconfirm
    if [ ${confirm} != 'n' -a ${confirm} != 'N' ]
    then
        if  [  ${confirm} != 'y' -a ${confirm} != 'Y' ]
        then
                 echo "\n **********  Warning - Invalid input -Please enter a valid input **********"
        else
        echo
        fi
    else
        echo "************ User terminated  ********"
        echo "\n Goodbye ... !!!"
        exit 0;
    fi
done

Any ideas:wall::wall::wall::wall::wall::wall:

You need to put double quotes around your variable references for this to work,for example:

while [  "${confirm}" != 'y' -a "${confirm}" != 'Y'  ]
etcetera

As well as the quotes, a case-statement is also suited to this sort of thing.

i.e.

YorN() {
  while true; do
    printf "${1:-Enter y or n}: "
    read ANSWER
    case "$ANSWER" in
      y|Y) return 0;;
      n|N) return 1;;
        *) echo "Wrong answer. Try again."
    esac
  done
}

YorN "Continue?"

echo $?