Bash скрипт универсальный распаковщик

Надоело мне для каждой программы сжатия использовать свои программы и ключи, и вылился этот порыв вот в такой скрипт:

#!/bin/bash
#
#

Z="compress -d"
gz="gunzip"
bz="bunzip2"
zip="unzip -qo"
rar="unrar x -id -y"
tar="tar xf"
7z="p7zip -d"

if [ $# -eq 0 ]; then
    echo "Usage: decompress file or files">&2
    exit 1
fi

for name
do
	if [ ! -f "$name" ] ; then
		echo "$0: file $name not found." >&2
		continue
	fi

	if [ "$(echo $name | egrep '(\.Z$|\.gz$|\.bz2$|\.zip$|\.rar$|\.tar$|\.tgz$|\.7z$)')" = "" ] ; then
		echo "Skipped file ${name}: it's already decompressed." 
      		continue
	fi

	extension=${name##*.}

	case "$extension" in
		Z ) echo "Filetype is Z. Decompressing..."
		    $Z "$name"
		    ;;
		gz ) echo "Filetype is gz. Decompressing..."
		     $gz "$name"
		     ;;
		bz2 ) echo "Filetype is bz2. Decompressing..."
 		     $bz "$name"
		     ;;
		zip ) echo "Filetype is zip. Decompressing..."
		      $zip "$name"
		      ;;
		rar ) echo "Filetype is rar. Decompressing..."
		      $rar "$name"
		      ;;
		tar ) echo "Filetype is tar. Decompressing..."
              	      $tar "$name"
              	      ;;
		tgz ) echo "Filetype is tgz. Decompressing..."
              	      $tar "$name"
                     ;;
               7z ) echo "Filetype is 7z. Decompressing..."
                     $7z "$name"
	esac

done

exit 0


Leave a Reply

Ваш адрес email не будет опубликован. Обязательные поля помечены *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>