How to compare ASCII char with octal number
am 05.11.2007 09:57:34 von PeterHi,
In the function below i select a random ASCII character (A-Z) which
must be pressed by a user.
The ASCII character is generated by printing a character in octal
notation. I need to compare
the key pressed by the end-user with the character represented by the
octal number. Therefore
i convert the octal number to a character using the print
instruction ;
uorg=`print "\0${randoctkey}"`
Is there a better/nicer way to do this ?
warnandwait() {
print "\nTHINK! Incorrect use of this tool can stop all
communications."
typeset -i i=0
while ((i <= 2));
do
print -n ".";
(( i = i + 1));
sleep 1
done
# generate random octal number in decimal 65-90
randoctkey=`echo "obase=8;$((RANDOM%(90-65+1)+65))"| bc`
print "\nPress the \"\0${randoctkey}\" key to continue"
uresp=`getch`
uorg=`print "\0${randoctkey}"`
if [[ $uorg != $uresp ]]
then
print "If even pressing the right key is a challenge,"
print "consider NOT using this script."
exit 1
fi