vim mytar.sh
#!/bin/bash # read -p "Three files:" file1 file2 file3 read -p "Destination:" DEST -->指定压缩存放目录及文件名称 read -p "Compress[gzip|bzip2}xz]:" COMP -->输入压缩的格式 case $COMP in gzip) tar -zcf ${DEST}.tar.gz $file1 $file2 $file3 ;; bzip2) tar -jcf ${DEST}.tar.bz2 $file1 $file2 $file3 xz) tar -cf ${DEST}.tar $file1 $file2 $file3 xz ${DEST}.tar ;; *) echo "Unknow." exit 9 ;; esac
测试脚本:
[[email protected] test]# pwd /mnt/test [[email protected] test]#chmod +x mytar.sh [[email protected] test]# ./mytar2.sh Input Three files:test1.txt test2.txt test3.txt Destination:/mnt/test/test Compress[gzip|bzip2|xz]:gzip [[email protected] test]# ls mytar.sh test2.txt test.tar.gz test1.txt test3.txt
时间: 2024-10-29 19:08:07