Shell练习(十五)
#!/bin/bash# date:2018年3月21日
if [ $# -ne 1 ] || [ ${#1} -ne 8 ]
then
echo "Usage: bash $0 yyyymmdd"
exit 1
fi
date=$1
year=${date:0:4}
month=${date:4:2}
day=${date:6:2}
if echo $day|grep -q '^0'
then
day=`echo $day|sed 's/^0//'`
fi
if cal $month $year > /dev/null 2> /dev/null
then
daym=`cal $month $year|grep -v "$year"|grep -w "$day"`
if [ "$daym" != "" ]
then
echo "ok"
else
echo "Error:Please input a right date"
exit 1
fi
else
echo "Error: Please input a right date"
exit 1
fi
页:
[1]