Guest User

Untitled

a guest
Jan 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. function main
  4. {
  5. local dest=.
  6.  
  7. while getopts 'd:' OPT
  8. do
  9. case $OPT in
  10. 'd') dest="$OPTARG" ;;
  11. esac
  12. done
  13.  
  14. shift $(expr $OPTIND - 1)
  15.  
  16. for file in "$@"
  17. do
  18. if [ -f "$file" ]
  19. then
  20. case "$file" in
  21. *.tar.bz2) tar xvfj "$file" -C "$dest/" ;;
  22. *.tar.gz) tar xvfz "$file" -C "$dest/" ;;
  23. *.tar.lzma) tar xvfa "$file" -C "$dest/" ;;
  24. *.tar.xz) tar xvfJ "$file" -C "$dest/" ;;
  25. *.tar) tar xvf "$file" -C "$dest/" ;;
  26. *.tbz) tar xvfj "$file" -C "$dest/" ;;
  27. *.tgz) tar xvfz "$file" -C "$dest/" ;;
  28. *.tlz) tar xvfa "$file" -C "$dest/" ;;
  29. *.txz) tar xvfJ "$file" -C "$dest/" ;;
  30. *.7z) 7z x "$file" -o"$dest/$(basename $file .7z)/" ;;
  31. *.bz2) bunzip2 "$file" ;;
  32. *.cab) cabextract -d "$dest/$(basename "$file" .cab)/" "$file" ;;
  33. *.deb) ar x "$file" ;;
  34. *.gz) gunzip "$file" ;;
  35. *.lha) lha xw="$dest/$(basename "$file" .lha)/" "$file" ;;
  36. *.lzma) lzma "$file" ;;
  37. *.rar) unrar x "$file" "$dest/$(basename "$file" .rar)/" ;;
  38. *.xz) xz "$file" ;;
  39. *.zip) unzip "$file" -d "$dest/$(basename "$file" .zip)/" ;;
  40. *) echo "'$file' cannot be extracted with extract." 1>&2 ;;
  41. esac
  42. else
  43. echo "'$file' is not a valid file." 1>&2
  44. fi
  45. done
  46. }
  47.  
  48. main "$@"
Add Comment
Please, Sign In to add comment