Advanced Bash-scripting Guide (17): use more to view gzip files,
The example selected in this article is from the book "Advanced Bash-scripting Gudie", translated by Yang chunmin Huang Yi
1 #! /Bin/bash 2 # use more to view the gzip file 3 4 NOARGS = 65 5 NOTFOUND = 66 6 NOTGZIP = 67 7 8 if [$ #-eq 0] # [$ #-eq 0] has the same effect as [-z "$1"] 9 then10 echo "Usage: 'basename $ 0' filename "> & 2 # output the error to the screen, & [n] indicates the existing file descriptor, & 2 indicates the standard error output, for example, if it is changed to &> 2, no error output is displayed on the screen. why? 11 exit $ NOARGS12 fi13 14 filename = $115 16 if [! -F "$ filename"] 17 then18 echo "File $ filename not found! "> & 2 # It is the same as above, except that stderr does not need to be redirected to the standard screen, because the standard error is output to the screen by default, so you can remove 19 exit $ NOTFOUND20 fi21 22 if [$ {filename ##*.}! = "Gz"] # Replace the variable and remove it. for all the previous strings, refer to echo $ {PATH # *:} on the 23rd page of ABS Chinese version to remove the first string: 23 then on the left. # Only determine the first ## farthest match # latest matching 24 echo "File $1 is not a gzipped file! "25 exit $ NOTGZIP26 fi27 28 zcat $1 | more # The zcat command is used to display the content of files in the compressed package 29 30 exit $?
Script running result