您的位置:首页 > 运维架构 > Shell

linux shell 编程示例

2015-01-02 15:31 169 查看
#这是一个模拟考勤管理系统

<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: