2025-02-24 04:42:45 +01:00
|
|
|
#! /bin/sh
|
|
|
|
# Zcat - Cat wrapper for compressed files.
|
|
|
|
# Copyright (C) 2009 Antonio Diaz Diaz.
|
|
|
|
#
|
|
|
|
# This script is free software: you have unlimited permission
|
|
|
|
# to copy, distribute and modify it.
|
|
|
|
|
|
|
|
LC_ALL=C
|
|
|
|
export LC_ALL
|
|
|
|
args=
|
2025-02-24 04:57:21 +01:00
|
|
|
default_prog=gzip
|
2025-02-24 04:44:01 +01:00
|
|
|
two_hyphens=0
|
2025-02-24 04:42:45 +01:00
|
|
|
|
2025-02-24 04:44:01 +01:00
|
|
|
# Loop over args until a filename is found
|
2025-02-24 04:42:45 +01:00
|
|
|
while [ x"$1" != x ] ; do
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
--help | --he* | -h)
|
|
|
|
echo "Zcat - Cat wrapper for compressed files."
|
|
|
|
echo
|
2025-02-24 04:57:21 +01:00
|
|
|
echo "Zcat is a wrapper script around the cat command that allows transparent"
|
|
|
|
echo "concatenation of any combination of compressed and non-compressed files."
|
|
|
|
echo "If any given file is compressed, its uncompressed content is used. If a"
|
|
|
|
echo "given file does not exist, zcat tries the compressed file names"
|
|
|
|
echo "corresponding to the supported compressors. If no files are specified,"
|
|
|
|
echo "the standard input is decompressed using the selected compressor and"
|
|
|
|
echo "sent to stdout."
|
2025-02-24 04:42:45 +01:00
|
|
|
echo "The supported compressors are gzip, bzip2, lzip and xz."
|
|
|
|
echo
|
2025-02-24 04:44:01 +01:00
|
|
|
echo "Usage: $0 [OPTIONS] [CAT_OPTIONS] [FILES]"
|
2025-02-24 04:42:45 +01:00
|
|
|
echo
|
|
|
|
echo "CAT_OPTIONS are passed directly to cat."
|
|
|
|
echo "The exit status from cat is preserved."
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo " -h, --help display this help and exit"
|
|
|
|
echo " -V, --version output version information and exit"
|
2025-02-24 04:57:21 +01:00
|
|
|
echo " --gzip use gzip as decompressor for stdin (default)"
|
|
|
|
echo " --bzip2 use bzip2 as decompressor for stdin"
|
|
|
|
echo " --lzip use lzip as decompressor for stdin"
|
|
|
|
echo " --xz use xz as decompressor for stdin"
|
2025-02-24 04:42:45 +01:00
|
|
|
echo
|
2025-02-24 04:44:01 +01:00
|
|
|
echo "Report bugs to zutils-bug@nongnu.org"
|
|
|
|
echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html"
|
2025-02-24 04:42:45 +01:00
|
|
|
exit 0 ;;
|
|
|
|
--version | --ve* | -V)
|
|
|
|
echo "Zcat VERSION"
|
|
|
|
echo "Copyright (C) 2009 Antonio Diaz Diaz."
|
|
|
|
echo "This script is free software: you have unlimited permission"
|
|
|
|
echo "to copy, distribute and modify it."
|
|
|
|
exit 0 ;;
|
2025-02-24 04:57:21 +01:00
|
|
|
--gz*)
|
|
|
|
default_prog=gzip ;;
|
|
|
|
--bz*)
|
|
|
|
default_prog=bzip2 ;;
|
|
|
|
--lz*)
|
|
|
|
default_prog=lzip ;;
|
|
|
|
--xz*)
|
|
|
|
default_prog=xz ;;
|
|
|
|
- | -f)
|
2025-02-24 04:42:45 +01:00
|
|
|
;;
|
|
|
|
--)
|
2025-02-24 04:44:01 +01:00
|
|
|
shift ; two_hyphens=1 ; break ;;
|
2025-02-24 04:42:45 +01:00
|
|
|
-?*)
|
|
|
|
args="${args} $1" ;;
|
|
|
|
*)
|
|
|
|
break ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2025-02-24 04:57:21 +01:00
|
|
|
if [ $# = 0 ]; then
|
|
|
|
${default_prog} -cdfq | cat ${args}
|
|
|
|
exit $?
|
|
|
|
fi
|
2025-02-24 04:42:45 +01:00
|
|
|
|
|
|
|
retval=0
|
|
|
|
for i in "$@" ; do
|
2025-02-24 04:44:01 +01:00
|
|
|
if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1
|
|
|
|
else
|
2025-02-24 04:51:33 +01:00
|
|
|
if [ ! -f "$i" ]; then
|
|
|
|
if [ -f "$i.gz" ]; then i="$i.gz"
|
|
|
|
elif [ -f "$i.bz2" ]; then i="$i.bz2"
|
|
|
|
elif [ -f "$i.lz" ]; then i="$i.lz"
|
|
|
|
elif [ -f "$i.xz" ]; then i="$i.xz"
|
|
|
|
else
|
|
|
|
echo "$0: File \"$i\" not found or not a regular file" 1>&2
|
|
|
|
if [ ${retval} = 0 ]; then retval=1 ; fi
|
|
|
|
continue
|
|
|
|
fi
|
2025-02-24 04:44:01 +01:00
|
|
|
fi
|
2025-02-24 04:51:33 +01:00
|
|
|
bindir=`echo "$0" | sed -e 's,[^/]*$,,'`
|
|
|
|
prog_name=`"${bindir}"zutils -t -- "$i"`
|
|
|
|
case "${prog_name}" in
|
|
|
|
gzip) prog="gzip -cdfq" ;;
|
|
|
|
bzip2) prog="bzip2 -cdfq" ;;
|
|
|
|
lzip) prog="lzip -cdfq" ;;
|
|
|
|
xz) prog="xz -cdfq" ;;
|
|
|
|
*) prog=cat ;;
|
|
|
|
esac
|
2025-02-24 04:44:01 +01:00
|
|
|
${prog} -- "$i" | cat ${args}
|
|
|
|
r=$?
|
|
|
|
if [ $r != 0 ]; then retval=$r ; fi
|
|
|
|
fi
|
2025-02-24 04:42:45 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
exit ${retval}
|