LDP/LDP/guide/docbook/abs-guide/ex14.sh

42 lines
946 B
Bash
Raw Permalink Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2005-03-21 13:51:11 +00:00
# zmore
2001-07-10 14:25:50 +00:00
2008-07-20 23:16:47 +00:00
# View gzipped files with 'more' filter.
2001-07-10 14:25:50 +00:00
2011-08-29 23:59:19 +00:00
E_NOARGS=85
E_NOTFOUND=86
E_NOTGZIP=87
2001-07-10 14:25:50 +00:00
if [ $# -eq 0 ] # same effect as: if [ -z "$1" ]
2005-03-21 13:51:11 +00:00
# $1 can exist, but be empty: zmore "" arg2 arg3
2001-07-10 14:25:50 +00:00
then
echo "Usage: `basename $0` filename" >&2
2001-07-10 14:25:50 +00:00
# Error message to stderr.
2008-07-20 23:16:47 +00:00
exit $E_NOARGS
2012-04-04 22:51:18 +00:00
# Returns 85 as exit status of script (error code).
2001-07-10 14:25:50 +00:00
fi
filename=$1
if [ ! -f "$filename" ] # Quoting $filename allows for possible spaces.
then
echo "File $filename not found!" >&2 # Error message to stderr.
2008-07-20 23:16:47 +00:00
exit $E_NOTFOUND
2001-07-10 14:25:50 +00:00
fi
if [ ${filename##*.} != "gz" ]
# Using bracket in variable substitution.
then
echo "File $1 is not a gzipped file!"
2008-07-20 23:16:47 +00:00
exit $E_NOTGZIP
2001-07-10 14:25:50 +00:00
fi
2005-03-21 13:51:11 +00:00
zcat $1 | more
2001-07-10 14:25:50 +00:00
2008-07-20 23:16:47 +00:00
# Uses the 'more' filter.
# May substitute 'less' if desired.
2001-07-10 14:25:50 +00:00
exit $? # Script returns exit status of pipe.
2008-07-20 23:16:47 +00:00
# Actually "exit $?" is unnecessary, as the script will, in any case,
#+ return the exit status of the last command executed.