カレンダスクリプト

アウトプット主義で。
LinuxUNIX)のcalコマンドは、

cal [-13smjyV] [[month] year]

となっているのだが、「month year」か「year month」かでよく迷う。
だから、いつもcalはmycal.shという自作シェルスクリプトを使う。

#!/bin/sh
CALOPT=
PARAM=
while getopts 13smjyV OPT
do
 CALOPT='-'
 case $OPT in
  1|3|s|m|j|y|V) CALOPT=$CALOPT$OPT ;;
 esac
done
shift `expr $OPTIND - 1`
if [ $# -gt 1 ]
then
 if [ $2 -gt 12 ]
 then
  PARAM="$1 $2"
 else
  PARAM="$2 $1"
 fi
else
 PARAM=$1
fi
cal $CALOPT $PARAM
exit 0

こうしておけば「month year」でも「year month」でも両方OK。
シェルスクリプトってこんな感じに気楽に書けるから良いですね。