Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- function main
- {
- local dest=.
- while getopts 'd:' OPT
- do
- case $OPT in
- 'd') dest="$OPTARG" ;;
- esac
- done
- shift $(expr $OPTIND - 1)
- for file in "$@"
- do
- if [ -f "$file" ]
- then
- case "$file" in
- *.tar.bz2) tar xvfj "$file" -C "$dest/" ;;
- *.tar.gz) tar xvfz "$file" -C "$dest/" ;;
- *.tar.lzma) tar xvfa "$file" -C "$dest/" ;;
- *.tar.xz) tar xvfJ "$file" -C "$dest/" ;;
- *.tar) tar xvf "$file" -C "$dest/" ;;
- *.tbz) tar xvfj "$file" -C "$dest/" ;;
- *.tgz) tar xvfz "$file" -C "$dest/" ;;
- *.tlz) tar xvfa "$file" -C "$dest/" ;;
- *.txz) tar xvfJ "$file" -C "$dest/" ;;
- *.7z) 7z x "$file" -o"$dest/$(basename $file .7z)/" ;;
- *.bz2) bunzip2 "$file" ;;
- *.cab) cabextract -d "$dest/$(basename "$file" .cab)/" "$file" ;;
- *.deb) ar x "$file" ;;
- *.gz) gunzip "$file" ;;
- *.lha) lha xw="$dest/$(basename "$file" .lha)/" "$file" ;;
- *.lzma) lzma "$file" ;;
- *.rar) unrar x "$file" "$dest/$(basename "$file" .rar)/" ;;
- *.xz) xz "$file" ;;
- *.zip) unzip "$file" -d "$dest/$(basename "$file" .zip)/" ;;
- *) echo "'$file' cannot be extracted with extract." 1>&2 ;;
- esac
- else
- echo "'$file' is not a valid file." 1>&2
- fi
- done
- }
- main "$@"
Add Comment
Please, Sign In to add comment