Capture an empty key press...

I am trying to test input from the user, if they press enter with out an Y or N. I have the characheter thing sorted but when it comes to a blank or empty key press I am having trouble.

if [ ${continue} = '' ]; then
clear
echo "Sorry, that is an invalid choice!"
exit
fi

I am using a KSH script in Solaris.

Thanks in advance.
:confused:

use a loop such as this
until [ $INPUT = Y ]
do
do some stuff here
done
to check to see that your variable is set properly based upon what the user typed in. The loop will continue to be executed until condition is TRUE. This is useful when the expected input is a Yes/No queston or of similar type.
Or
check to see that the variable you use to capture standard input is actually set. You can do this by checking or an empty string. Your code was close but you were either using single quotes or were missing an end double quote.

echo " Enter Some Input Data: \c"
read INPUT

if [ ${INPUT} = ''" ]; then
clear
echo "Sorry, that is an invalid choice!"
exit
fi

You need to quote the input variable or use double square brackets...

if [ "$continue" = "" ]

OR

if [[ ${continue} = '' ]]

Sorted, thanks very much google.

:slight_smile: