#这是一个模拟考勤管理系统
<span style="font-family:Courier New;font-size:14px;">#!/bin/bash
login()
{
username=$1
userpassword=$2
IFS=":"
while read name password
do
name=`echo $name`
password=`echo $password`
if [ "$username" == "$name" ] && [ "$userpassword" == "$password" ];then
ret=1
echo $ret
return
fi
done<userinfo.dat
ret=0
echo $ret
return
}
menu()
{
echo "1.check in"
echo "2.check out"
echo "3.query"
}
nowhour=`date +%H`
if [ $nowhour -lt 12 ];then
echo "good morning!"
else
echo "good afternoon!"
fi
echo -n "name:"
read name
echo -n "password:"
read password
result=`login $name $password`
if [ $result -eq 0 ];then
echo "login failed!"
exit
else
echo "login success!"
fi
menu
read choice
case $choice in
1 )
if [ $nowhour -gt 8 ];then
echo "too late"
echo "$name check late `date`">check.dat
else
echo "checked!"
echo "$name checked at `date`">check.dat
fi;;
2 )
if [ $nowhour -lt 18 ];then
echo "too early"
echo "$name check early `date`">check.dat
else
echo "checked!"
echo "$name checked at `date`">check.dat
fi;;
3 ) echo "your choice is 3";;
* ) echo "err!";;
esac</span>