shell脚本----简单日记系统

#b.sh 首页(登录界面):

echo "------->haha<-------";
echo "  1、登录";
echo "  2、注册";
echo "  3、退出";
echo
read -p "" a;
case "$a" in
1)
    clear ; #清屏!
A () {
   echo "++++++登录界面++++++"
   read -p "用户名:" n;
   read -s -p "密码:" pw;
    echo;
   while [ -z $n ] & [ -z $pw ] ;do
            echo "用户名或密码为空!请重新输入!";
            A;
   done
 }
    A;
   name=`cat /root/shell/ming/1.txt | grep -w $n | cut -d " " -f 1`;
    if [ -z $name ] ;then
            echo "用户不存在";
            read -p "是否注册(y/n)" a1;
                    if [ $a1 == y ] ;then
                            /root/shell/ming/a.sh ;
                    else
                            A;
                    fi
    fi
   passwd=`cat /root/shell/ming/1.txt | grep -w $n | cut -d " " -f 4`;
    if [ -z $pw ] ;then
            echo "密码不能为空!";
            A;
    fi
    if [ $name = $n ] && [ $passwd = $pw ] ;then
            echo "登陆成功!";
            /root/shell/ming/c.sh ;
   else
            echo "用户名或密码错误!";
            /root/shell/ming/b.sh ;
   fi
;;
2)
    clear ;
  /root/shell/ming/a.sh
  echo "用户创建成功!";
;;
3)
    clear ;
  echo "已退出!";
;;
*)
  /root/shell/ming/b.sh
;;
esac

#a.sh 用于注册,信息存放在1.txt中:

name () {
    read -p "用户名:" n;
    while [ -z $n ] ;do
            name;
    done
}
sex () {
    read -p "性别:" s;
    if [ $s = "男" -o $s = "女" ] ;then
            age;
    else
            echo "请选择有效性别,谢谢!";
            sex;
    fi
}
age () {
    read -p "年龄:" a;
    while [ -z $a ] ;do
            age;
    done
}
passwd () {
    read -s -p "密码:" pw;
    while [ -z $pw ] ;do
            echo "密码不能为空!";
            passwd;
    done
}
name;
sex;
passwd;
echo "用户信息:$n ,$s ,$a";
echo "$n $s $a $pw" >> 1.txt
echo "用户创建成功!";
/root/shell/ming/b.sh ;

#c.sh 主页面(写日记,查看,删除)

read -p "
+++++++Welcome+++++++
 ------To------
1、写日记;
2、查看日记;
3、删除日记;
4、退出登录;
" a;
i=`ls /root/shell/ming/a | wc -l`;
case "$a" in
1)
    clear ;
#写日记到用户目录;
    echo "y:保存!";
    echo "n:退出!";
    read -p "
-------草稿---------
" a;
    read -p "是否保存(y/n)" b;
    if [ $b == y ] ;then
            j=`expr $i + 1` ;
            echo $a >> a/$j;
            /root/shell/ming/c.sh ;
    else
            echo "已退出!";
            /root/shell/ming/c.sh ;
    fi
;;
2)
    clear ;
#查看日记;
    echo `ls /root/shell/ming/a` ;
    read -p "选择您要查看的日记:" b;
    b1=`ls /root/shell/ming/a | grep $b`
    if [ -n $b1 ] ;then
            cat /root/shell/ming/a/$b1 ;
            /root/shell/ming/c.sh ;
    else
            echo "文件不存在!";
            /root/shell/ming/c.sh ; #循环到开始界面;
    fi
;;
3)
    clear ;
#删除日记;
    echo "`ls /root/shell/ming/a`";
    read -p "选择要删除的日记:" a;
    b=`ls /root/shell/ming/a | grep -w $a` ;
    if [ -z $b ] ;then
            echo "文件不存在!";
            /root/shell/ming/c.sh ;
    else
            rm -rf /root/shell/ming/a/$b ;
            /root/shell/ming/c.sh ;
    fi
;;
4)
    clear ;
#退出登录
    /root/shell/ming/b.sh ;
;;
*)
    echo "操作不当!";
    /root/shell/ming/c.sh ;
;;
esac
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值