用shell写一个日记程序

#!/bin/bash

declare -x mark=unquit
while [ “${mark}” != “quit” ]
do
echo -en “enter (copy) to copy a file.\nenter (settings) to print the settings.\nenter (gus) to have a game guess a number 0-9.\nenter (date) to show the second right now.\nenter (diary) to write today’s things at diary after read.\nenter (set) to set new diary route or read your old diary.\nenter (none) read y to quit.\n”

read -p "so enter a str to use function: " vary
case ${vary} in
  "copy")
    read -p "enter the file name in absolute path:" path1
    read -p "enter the aim path" path2
    cp -a path1 path2
    ;;
  "settings")
    echo "YOUR home catalogue: "
    echo -n $HOME
    echo "--------------------------------------"
    echo "YOUR shell: "
    echo -n $SHELL
    echo "--------------------------------------"
    echo "YOUR route right now: "
    echo -n $PWD
    echo "--------------------------------------"
    echo "YOUR username: "
    echo -n $USER
    echo "--------------------------------------"
    echo "TIME: "
    date
      ;;
  "gus")
    read -p "enter a number: " nm
    declare -i number=$RANDOM*10/32768
    [ "$nm" == "$number" ] && echo "RIGHT!!" || echo "YOU are wrong,the number is $number"
    ;;
  "date")
    echo $(date +%s)
    ;;
  "diary")
    read -p "START to write now! " diary
    echo $(date) >> $path_diary
    echo $diary >> $path_diary
    cat -An $path_diary
    ;;
  "set")
    read -p "enter R to read one,S to set one: " DIARY
    case $DIARY in
      "R")
        echo "--help:the path is /home/work/diarys/(your diary name)"
        read -p "enter the absolute path:" path_diary
        declare -x path_diary
        ;;
      "S")
        read -p "enter the diary name:" filename
        touch /home/work/diarys/$filename
        echo "set success! enter set again to read the diaryname you just creat!"
        ;;
      "*")
        echo "wrong arr!"
        exit 1
        ;;
    esac
      ;;
  "none")
    echo "ready to quit"
    ;;                   
  "*")
    echo "WRONG!"
    exit 1
    ;;
esac
read -p "enter quit to end,enter unquit to continue: " mark

done

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值