| 1 | #!/bin/bashscip-shell filesystem . . `/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 [scip-shell system . . `[`. $# -eq 0 ] # same effect as: if [ -z "$1" ] |
| 11 | # $1 can exist, but be empty: zmore "" arg2 arg3 |
| 12 | then |
| 13 | echoscip-shell system . . echo. "Usage: `basenamescip-shell system . . 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 [scip-shell system . . `[`. ! -f "$filename" ] # Quoting $filename allows for possible spaces. |
| 22 | then |
| 23 | echoscip-shell system . . echo. "File $filename not found!" >&2 # Error message to stderr. |
| 24 | exit $E_NOTFOUND |
| 25 | fi |
| 26 | |
| 27 | if [scip-shell system . . `[`. ${filename##*.} != "gz" ] |
| 28 | # Using bracket in variable substitution. |
| 29 | then |
| 30 | echoscip-shell system . . echo. "File $1 is not a gzipped file!" |
| 31 | exit $E_NOTGZIP |
| 32 | fi |
| 33 | |
| 34 | zcatscip-shell system . . zcat. $1 | morescip-shell system . . 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. |