07.sh
#!/bin/bash
read -p "请输入年月日" year mouth day
a=0
if [ $(($year%400)) -eq 0 -o $(($year%4)) -eq 0 -a $(($year%100)) -ne 0 ]
then
let a+=1
fi
if [ $mouth -gt 0 -a $mouth -le 12 ]
then
flag=0
case $mouth in
[13578]|10|12)
if [ $day -gt 0 -a $day -le 31 ]
then
((flag=0))
else
((flag=1))
fi
;;
2)
if [ $day -gt 0 -a $day -le $((28+$a)) ]
then
((flag=0))
else
((flag=1))
fi
;;
*)
if [ $day -gt 0 -a $day -le 30 ]
then
((flag=0))
else
((flag=1))
fi
;;
esac
if [ $flag -eq 0 ]
then
today=0;
case $mouth in
1)
let today=${day};;
2)
today=$((31+$day));;
3)
today=$((31+28+$a+$day));;
4)
today=$((30*3+$a+$day));;
5)
today=$((30*4+$a+$day));;
6)
today=$((30*5+1+$a+$day));;
7)
today=$((30*6+1+$a+$day));;
8)
today=$((30*7+2+$a+$day));;
9)
today=$((30*8+3+$a+$day));;
10)
today=$((30*9+3+$a+$day));;
11)
today=$((30*10+4+$a+$day));;
12)
today=$((30*11+4+$a+$day));;
esac
echo "这是今年的第$today天"
else
echo "天数输入错误"
fi
else
echo "月份输入错误"
fi
08.sh
输入数字求和
#!/bin/bash
read -p "请输入数字" a b
for i in $(seq $a $b)
#for i in {1..100}
#for((i=0;i<=100;i++))
#for i
do
((sum+=$i))
done
echo $sum
九九乘法表
09.sh
#!/bin/bash
for i in {1..9}
do
for j in `seq $i 9`
do
echo -n "$i x $j = $(($i*$j)) "
done
echo
done