入门级shell练习题7


    创建或目录文件
   - 该脚本应当有交互功能
   - 该脚本用于备份系统目录
   - 需要给予用户提示,提示用户应当输入目录或者文件名
   - 判断用户要备份的文件是否存在,如果不存在则告知用户,并输出相应错误
   - 判断用户要备份的目标目录是否存在,如果该目录不存在,则需要问用户是否创建,如果该目录已经存在,则需要问用户是否重命名该目录

#!/bin/bash
#This is a shell for backup the system dir
read -p "Please input your dir : " dir
read -p "please input your backup file: " file
if [ -e $file ]
then
   echo "The $file is already exisit,you do not need make again"
else
   echo "This $file is not exsit, please back up it first"
   tar -czvf targettar.tar.gz $dir
fi

if [ -e $dir ]
then
    echo "This $dir is exsit,are you sure to move this $dir"
else
    echo "This $dir is not exsit,please make dir first"
fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值