/home/wpollock1/public_html/restricted/ShellScripting/magic8ball
#!/bin/sh -
# Displays an answer to any question. Uses the 20
# possible answers from the original "Magic 8 Ball" toy
# made by Mattel. See https://en.wikipedia.org/wiki/Magic_8-Ball
#
# Written 12/2015 by Wayne Pollock, Tampa Florida USA
#
# The date command is used to get a different answer even if the
# question is the same text.
if [ $# -eq 0 ]; then
echo "Usage: ${0##*/} your question here..."
exit 1
fi
NUM=$(echo "$(date +%S)$*" |cksum |cksum |xargs -I'{}' expr '{}' : '.*\([0-9][0-9]\) ')
NUM=$( expr $NUM % 20 ) # Cannot use $((...)) safely when NUM might be '09'
case "$NUM" in
(0) echo It is certain ;;
(1) echo It is decidedly so ;;
(2) echo Without a doubt ;;
(3) echo Yes, definitely ;;
(4) echo You may rely on it ;;
(5) echo As I see it, yes ;;
(6) echo Most likely ;;
(7) echo Outlook good ;;
(8) echo Yes ;;
(9) echo Signs point to yes ;;
(10) echo Reply hazy try again ;;
(11) echo Ask again later ;;
(12) echo Better not tell you now ;;
(13) echo Cannot predict now ;;
(14) echo Concentrate and ask again ;;
(15) echo "Don't count on it" ;;
(16) echo My reply is no ;;
(17) echo My sources say no ;;
(18) echo Outlook not so good ;;
(*) echo Very doubtful ;;
esac