zoukankan      html  css  js  c++  java
  • 脚本练习一:备份与删除

    第一次练习,代码比较臃肿,主要就是用for循环来写的。
    #!/bin/bash while true do echo "##############################" echo "##### 1 Copy ######" echo "##### 2 Delete ######" echo "##### 3 Quit ######" echo "##############################" read -p "Please select you want to do: " num if [ $num -eq 1 ];then echo "You choose is:COPY" echo "**********************************************************" echo "*Note: the file name you entered can only is the current directory or the absolute path of files.*" echo "**********************************************************" read -p "Please enter your copy of the file or directory:" file if [ ! -e $file ];then echo "$file is not exist" echo "please input again: " continue fi read -p "Please enter a target directory: " dir if [ ! -e $dir ];then echo "$dir is not exist" echo "please input again: " continue fi if [ -f $dir ];then echo "$dir is a file,not a directory" echo "please input again: " continue fi if [ -d $dir ];then echo "Are you sure want to copy file to: $dir" echo "Yes! input 'y' " echo "No! input 'n'" read -n 1 keys if [ $keys == y ];then echo cp -a $file $dir if [ $? ];then echo "*******`date '+%Y-%m-%d %H:%M:%S'`*******" echo "Copy $file success" echo "*********************************" sleep 2 else echo "Copy $file failed" sleep 2 exit 13 fi elif [ $keys == n ];then echo "Program exits" sleep 2 exit 14 fi fi continue fi if [ $num -eq 2 ];then echo "You choose is:Delete" read -p "Please input you want to delete the target file directory:" dir_del if [ ! -e $dir_del ];then echo "$dir_del is not exist" echo "please input again! " continue elif [ -f $dir_del ];then echo "Input $dir_del is a file,Please enter the directory first" continue elif [ -d $dir_del ];then read -p "Please input you want to delete the target file_name: " file_del if [ ! -e $file_del ];then echo "$file_del is not exist" echo "please input again! " continue elif [ -d $file_del ];then echo "Input $file_del is a directory,Please enter a file" continue elif [ -f $file_del ];then echo "input 'y'" echo "input 'n'" echo read -n 1 keys_del if [ $keys_del == y ];then cd $dir_del rm -f $file_del if [ $? ];then echo echo "*******`date '+%Y-%m-%d %H:%M:%S'`*******" echo "Delete file success!" echo "*********************************" sleep 2 else echo "Delete file failed" sleep 2 exit 15 fi elif [ $keys_del == n];then echo "Program exits" sleep 2 exit 16 fi fi fi continue fi if [ $num -eq 3 ];then exit fi done

      

  • 相关阅读:
    Android 开发 深入理解Handler、Looper、Messagequeue 转载
    Android 开发 Handler的基本使用
    Java 学习 注解
    Android 开发 AlarmManager 定时器
    Android 开发 框架系列 百度语音合成
    Android 开发 框架系列 Google的ORM框架 Room
    Android 开发 VectorDrawable 矢量图 (三)矢量图动画
    Android 开发 VectorDrawable 矢量图 (二)了解矢量图属性与绘制
    Android 开发 VectorDrawable 矢量图 (一)了解Android矢量图与获取矢量图
    Android 开发 知晓各种id信息 获取线程ID、activityID、内核ID
  • 原文地址:https://www.cnblogs.com/miaoxg/p/5289616.html
Copyright © 2011-2022 走看看