I'm writing a a Horoscope RSS script as an intro to Unix/Linux project, and ran into an issue my Professor couldn't fix in the time I was able to stay after class. Since I couldn't figure out how to use actual dates as what to check, I thought I'd try basic arithmetic by having user input be standard numbers in MMDD format. According to him, the script seems to be reading input as octal code instead of integer. Here's a sample of the script:
elif [ "$olddate" -gt 1121 ] && [ "$olddate" -lt 1131 ] || [ "$olddate" -gt 1200 ] && [ "$olddate" -lt 1222 ] then echo "You are Sagittarius" exit elif [ "$olddate" -gt 1221 ] && [ "$olddate" -lt 1232 ] || [ "$olddate" -gt 0100 ] && [ "$olddate" -lt 0120 ] then echo "You are Capricorn" exit
This is the bare bones, I took out the RSS part. "olddate" is the expected input from my read prompt. While 1121 to 1131, 1200 to 1222, and 0100 to 0120 work, nothing between 1221 to 1232 does. He figured that was the problem since putting 113 without a leading 0 worked for Capricorn. I also just ran into a problem where 0323 which was supposed to give me Aries (-gt 0320 && -lt 0332) gave me Aquarius (whose dates are -gt 0119 && -lt 0132 || -gt 0200 && -lt 0219) as well as 0417 not working (which is the other date range for Aries, -gt 0400 && -lt 0420).
What do I do so that BASH interprets input as the actual numbers? He tried changing the read prompt to expect "userdate" as input and then adding
olddate=`printf '%d\n' "$userdate"`
but that did not work. Thanks in advance to anyone who can help me out on this!