标签:写一个脚本 从键盘让用户输入几个文件 脚本能够将此几个文件归档压缩成一个文件
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测试脚本:
[root@localhost test]# pwd /mnt/test [root@localhost test]#chmod +x mytar.sh [root@localhost test]# ./mytar2.sh Input Three files:test1.txt test2.txt test3.txt Destination:/mnt/test/test Compress[gzip|bzip2|xz]:gzip [root@localhost test]# ls mytar.sh test2.txt test.tar.gz test1.txt test3.txt
本文出自 “小曾” 博客,请务必保留此出处http://zengxin.blog.51cto.com/6098070/1688086
写一个脚本 从键盘让用户输入几个文件,脚本能够将此几个文件归档压缩成一个文件
标签:写一个脚本 从键盘让用户输入几个文件 脚本能够将此几个文件归档压缩成一个文件
原文地址:http://zengxin.blog.51cto.com/6098070/1688086