4 # @(#) untar.ksh 1.0 93/11/10
5 # 92/10/08 john h. dubois iii (john@armory.com)
6 # 92/10/31 make it actually work if archive isn't in current dir!
7 # 93/11/10 Added pack and gzip archive support
9 # conversion to bash v2 syntax done by Chet Ramey
14 "$name: extract tar archives into directories, uncompressing if neccessary.
15 Usage: $name archive[.tar[.[Z|gz]]] ..
16 If an archive name given does not end in .tar, .tar.Z, or .tar.gz, it is
17 searched for first with .tar added, then .tar.Z, and then .tar.gz added.
18 The real filename must end in either .tar, .tar.Z, or .tar.gz. A
19 directory with the name of the archive is created in the current directory
20 (not necessarily the directory that the archive is in) if it does not
21 exist, and the the contents of the archive are extracted into it.
22 Absolute pathnames in tarfiles are suppressed."
36 *.
tar.Z
) ArchiveName
=${file%%.tar.Z} zcat
=zcat
;;
37 *.
tar.z
) ArchiveName
=${file%%.tar.z} zcat
=pcat
;;
38 *.
tar.gz
) ArchiveName
=${file%%.tar.gz} zcat
=gzcat
;;
40 for ext
in "" .Z .z .gz
; do
41 if [ -f "$file.tar$ext" ]; then
46 if [ ! -f "$file" ]; then
47 echo "$file: cannot find archive." 1>&2
52 if [ ! -r "$file" ]; then
53 echo "$file: cannot read." >&2
56 DirName
=${ArchiveName##*/}
57 [ -d "$DirName" ] ||
{
59 echo "$DirName: could not make archive directory." 1>&2
65 echo "$name: cannot cd to $DirName" 1>&2
74 echo "Extracting archive $file into directory $DirName..."
76 *.
tar.Z|
*.
tar.z|
*.
tar.gz
) $zcat $file |
tar xvf
-;;
77 *.
tar) tar xvf
$file;;
79 echo "Done extracting archive $file into directory $DirName."