// Decompresses Z, gz, bz2, zip, rar, tar, and 7z with a single 'decompress' command
1
2
3
4
5
6 Z="compress -d"
7 gz="gunzip"
8 bz="bunzip2"
9 zip="unzip -qo"
10 rar="unrar x -id -y"
11 tar="tar xf"
12 7z="p7zip -d"
13
14 if [ $
15 echo "Usage: decompress file or files to decompress">&2
16 exit 1
17 fi
18
19 for name
20 do
21 if [ ! -f "$name" ] ; then
22 echo "$0: file $name not found. Skipped." >&2
23 continue
24 fi
25
26 if [ "$(echo $name | egrep '(\.Z$|\.gz$|\.bz2$|\.zip$|\.rar$|\.tar$|\.tgz$|\.7z$)')" = "" ] ; then
27 echo "Skipped file ${name}: it's already decompressed."
28 continue
29 fi
30
31 extension=${name
32
33 case "$extension" in
34 Z ) echo "Filetype is Z. Decompressing..."
35 $Z "$name"
36 ;;
37 gz ) echo "Filetype is gz. Decompressing..."
38 $gz "$name"
39 ;;
40 bz2 ) echo "Filetype is bz2. Decompressing..."
41 $bz "$name"
42 ;;
43 zip ) echo "Filetype is zip. Decompressing..."
44 $zip "$name"
45 ;;
46 rar ) echo "Filetype is rar. Decompressing..."
47 $rar "$name"
48 ;;
49 tar ) echo "Filetype is tar. Decompressing..."
50 $tar "$name"
51 ;;
52 tgz ) echo "Filetype is tgz. Decompressing..."
53 $tar "$name"
54 ;;
55 7z ) echo "Filetype is 7z. Decompressing..."
56 $7z "$name"
57 esac
58
59 done
60
61 exit 0