File: zzcat

package info (click to toggle)
comprez 2.7.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 164 kB
  • sloc: sh: 528; makefile: 51
file content (40 lines) | stat: -rwxr-xr-x 663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh -
umask 077

# zzcat - uncompress stdin and/or files to stdout
# Steve Kinzler, steve@kinzler.com, Nov 11
# http://kinzler.com/me/home.html#unix

case "$#" in
0)	set x -; shift;;
esac

tmp=/tmp/zzcat$$
trap "rm -f $tmp; exit" 0 1 2 13 15

for file
do
	in="$file"
	case "$file" in
	-)	cat > $tmp
		in=$tmp
		case "`file $tmp`" in	# warning, heuristic
		*gzip*)		file=.gz;;
		*bzip2*)	file=.bz2;;
		*lzip*)		file=.lz;;
		*xz*)		file=.xz;;
		*compress*)	file=.Z;;
		*)		file=;;
		esac;;
	esac

	case "$file" in
	*.gz|*.z)	gzip  -d -n;;
	*.bz2)		bzip2 -d;;
	*.lz)		lzip  -d;;
	*.xz)		xz    -d;;
	*.Z)		uncompress;;
	*)		cat;;
	esac < "$in"
	rm -f $tmp
done