shell指令碼----簡單日記系統
阿新 • • 發佈:2018-12-19
#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