作为一个linux新手,挺喜欢shell脚本的,学习后写了日记脚本,具备分期存储功能,对于这个功能挺满意的,后来又加上关键字查找功能,以后的日记就用它了,将代码分享如下:
}
cmode() # create mode
{
echo "in the mode of create"
echo " create as you like"
if [ -d "$directory$time/" ] #test have wirtten dairy or not
then
echo "you have written dairy today"
echo "you can choose modify(m) or create a new one(c):"
read choose #choose to modify or create
if [ $choose = m ]
then
ls -a $directory$time/
echo "please choose the name to modify"
read modify_name
gvim $directory$time/$modify_name
elif [ $choose = c ]
then echo "please choose the name to create"
read create_name
echo "please choose whether to show log(y/n):"
read show_log
gvim $directory$time/$create_name
if [ $show_log = y ]
then
gvim ${directory}log
fi
else
echo "input wrong ,quit"
exit
fi
else #create a new file
echo "you can write the first dairy today"
mkdir $time
echo "choose the name to create"
read create_name
gvim $directory$time/$create_name
echo ${time} >>${directory}log #modify the log
gvim ${directory}log
fi
}
echo "please choose into grep mode or create mode(g/c)" #choose the right mode
read choose_mode
while true
do
if [ ${choose_mode} = g ]
then
echo "choose into the grep mode"
echo " "
gmode;
rm ${directory}store
elif [ ${choose_mode} = c ]
then
echo "choose into the create mode"
cmode;
else
echo "input error"
fi
echo "to leave"
break
done