linux shell 编程示例

#这是一个模拟考勤管理系统


<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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值