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

      

  • 相关阅读:
    git 之gitignore 添加项之后生效的问题
    使用 padding-bottom 设置高度基于宽度的自适应
    ES5中新增的Array方法详细说明
    zepto.js 自定义打包集成其他模块构建流程
    移动端如何让页面强制横屏
    快来看看抓包工具有哪些?
    实践出真知,小程序wepy,uni-app框架开发使用!
    开发过程遇到的css样式问题记录
    带坑使用微信小程序框架WePY组件化开发项目,附带第三方插件使用坑
    微信 + weui 框架记录
  • 原文地址:https://www.cnblogs.com/miaoxg/p/5289616.html
Copyright © 2011-2022 走看看