Advanced Bash-scripting Guide (17): use more to view gzip files,

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.