Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. Usage(){
  4. echo "usage: e.sh [--list] or [Source compressed file]"
  5. echo " [Destination path]"
  6. echo "Self uncompression accroding to the file name suffix"
  7. echo " "
  8. echo "eg. e.sh docker-18.06.tgz /path/to/data"
  9. exit
  10. }
  11.  
  12. #提示支持的解压类型
  13. List(){
  14. echo "Supported file types: zip tar tar.gz tgz tar.bz2"
  15. exit
  16. }
  17.  
  18. filename=$1
  19. #解压到路径名
  20. path=$2
  21. #获取文件名的后缀
  22. ext="${filename##*.}"
  23.  
  24. #判断用户是否输入了第一参数
  25. if [ -z $filename ]; then
  26. Usage;
  27. elif [ $filename = '--list' ]; then
  28. List;
  29. elif [[ -n $filename && -n $path ]]; then
  30. case $ext in
  31. 'tar')
  32. eval "tar xvf $filename -C $path";;
  33. 'gz')
  34. eval "tar zxvf $filename -C $path";;
  35. 'tgz')
  36. eval "tar zxvf $filename -C $path";;
  37. 'bz2')
  38. eval "tar jxvf $filename -C $path";;
  39. 'zip')
  40. eval "unzip $filename -d $path";;
  41. *)
  42. echo 'error(101) This type is not supported(tar|gz|bz2|zip)';;
  43. esac
  44. echo "done"
  45. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement