Solved! Go to Solution.
>JRF: your code would fail for August and September (months 8 and 9):
I was thinking I might have a problem like that.
>The shell interprets numeric values with a leading zero as octal numbers.
This is broken, and C Standard is broken. A better language design to change the radix, should have used something explicit: 0o777
If you want the month names from the locale can do something like the following thread:
Just a thought.
curMon=$(date '+%b');
case ${curMon} in
Jan ) prvMon="Dec" ;;
Feb ) prvMon="Jan" ;;
Mar ) prvMon="Feb" ;;
Apr ) prvMon="Mar" ;;
May ) prvMon="Apr" ;;
Jun ) prvMon="May" ;;
Jul ) prvMon="Jun" ;;
Aug ) prvMon="Jul" ;;
Sep ) prvMon="Aug" ;;
Oct ) prvMon="Sep" ;;
Nov ) prvMon="Oct" ;;
Dec ) prvMon="Nov" ;;
esac
Couldn't help but play with the array version.
#!/usr/bin/ksh
set -A pMonths Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov ;
(( prvMonthNum=$(( $(date '+%m') - 1 )) ));
prvMon=${pMonths[${prvMonthNum}]};