echo enter your year and month read year read month Y=$year M=$month printf "%3s %3s %3s %3s %3s %3s %3s\n" 日 月 火 水 木 金 土 if [ $M=1 ] || [ $M=2 ] then m=`expr $((M + 12 ))` else m=$M fi a=`expr$((Y/4))` b=`expr$((Y/100))` c=`expr$((Y/400))` d=`expr$((m+1))` e=`expr$((26*d/10))` f=`expr$((Y+a-b+c+e))` w=`expr$((f%7))` #1日の曜日を求める if [ $M=2 ] then if [ $Y%4=0 ] then if [ $Y%100=0 ] then if [ $Y%400=0 ] then day=29 else day=28 fi else day=29 fi else day=28 fi #閏年の計算 else if [ $M=4 ] || [ $M=6 ] || [ $M=9 ] || [ $M=11 ] then day=30 else day=31 #2月以外の日数の計算 fi case $w in 1) printf %3d #wの数だけタブを入力--1 while [ n -ge #day ] do printf n if [ $w=6 ] then printf "%3d/n" fi done #まず1日の曜日をもとめ、数字を書き始める場所を指定できるようにする #その後閏年の計算や場合わけで30日までか31日までを決定。 #1でwの数だけスペースを入力して、 #次のwhile文で日数と同じ回数だけ、実行回数目の数字をプリントしていく。 #ただし、if文で土曜日になる日付が来た時は改行処理をする。 #printfのスペースや改行の入れ方がよくわからず実行できませんでした。 #\tがスペースの処理に何かつかえそうな気がするのですが。