Vim mytar.sh
#!/bin/bash#read-p "Three files:" File1 file2 file3read-p "Destination:" DEST--Specify compressed directory and file name read-p "compress[gzip| BZIP2}XZ]: "COMP--Input compressed format case $COMP ingzip) tar-zcf ${dest}.tar.gz $file 1 $file 2 $file 3;; bzip2) tar-jcf ${dest}.tar.bz2 $file 1 $file 2 $file 3xz) tar-cf ${dest}.tar $file 1 $file 2 $file 3 XZ ${dest}.tar; *) echo "unknow." Exit 9;; Esac
Test script:
[[email protected] test]# Pwd/mnt/test[[email protected] test] #chmod +x mytar.sh[[email protected] test]#./mytar2.sh INP UT three files:test1.txt test2.txt test3.txtdestination:/mnt/test/test compress[gzip|bzip2|xz]:gzip[[email protected ] test]# lsmytar.sh test2.txt test.tar.gztest1.txt test3.txt
This article is from "Xiao Zeng" blog, please be sure to keep this source http://zengxin.blog.51cto.com/6098070/1688086
Write a script from the keyboard to let the user enter a few files, the script can archive this several files compressed into a file