Debian Codegraph @

ex14.sh

raw symbols SCIP
1 #!/bin/bash
2 # zmore
3
4 # View gzipped files with 'more' filter.
5
6 E_NOARGS=85
7 E_NOTFOUND=86
8 E_NOTGZIP=87
9
10 if [ $# -eq 0 ] # same effect as: if [ -z "$1" ]
11 # $1 can exist, but be empty: zmore "" arg2 arg3
12 then
13 echo "Usage: `basename $0` filename" >&2
14 # Error message to stderr.
15 exit $E_NOARGS
16 # Returns 85 as exit status of script (error code).
17 fi
18
19 filename=$1
20
21 if [ ! -f "$filename" ] # Quoting $filename allows for possible spaces.
22 then
23 echo "File $filename not found!" >&2 # Error message to stderr.
24 exit $E_NOTFOUND
25 fi
26
27 if [ ${filename##*.} != "gz" ]
28 # Using bracket in variable substitution.
29 then
30 echo "File $1 is not a gzipped file!"
31 exit $E_NOTGZIP
32 fi
33
34 zcat $1 | more
35
36 # Uses the 'more' filter.
37 # May substitute 'less' if desired.
38
39 exit $? # Script returns exit status of pipe.
40 # Actually "exit $?" is unnecessary, as the script will, in any case,
41 #+ return the exit status of the last command executed.