I assume from your title that you would like it to be locale independent. Since the man page for
date says it works in the locale, it is just the thing to use; not to mention a
case statement:
Code:
#! /bin/bash
#0 month.sh === print locale month abbr. from number
#@ by f.a.archibald.iii all rights reserved
_usage () {
cat << end_usage
month.sh print locale month abbr. from month number
Syntax: month.sh <number_of_month>
end_usage
}
case $1 in
[1-9]|1[0-2]) date -d "$1/01" +%b ;;
*) _usage ; exit 1
esac
And here is some test code:
Code:
chmod 755 month.sh
for ((x=0;$x<14;x++)) do
echo -ne "$x\t"
./month.sh $x
echo -e "\033[A\t\t exit code is $?"
done
EDIT: Drat,
jdiemer posted while I was composing & testing.
The core command is the same, though.