Shell decompression script

Source: Internet
Author: User

The case expression can be used to match a given string, not a number (do not confuse switch... case in C ).

Case... in...) do something here esac

The file command can identify the file type of a given file, for example, file lf.gz. The output result is:

Lf.gz: gzip compressed data, deflated, original filename, last modified: Mon Aug 27 23:09:18 2001, OS: Unix

We use this to write a script named smartzip, which can automatically decompress Bzip2, Gzip, and zip compressed files:

#! /Bin/sh FTYPE = 'file "$1" '# Note' and 'is different case "$ FTYPE" in "$1: ZIP Archive "*) unzip "$1"; "$1: gzip COMPRESSED" *) gunzip "$1"; "$1: Bzip2 COMPRESSED" *) bunzip2 "$1 ";; *) echo "File $1 can not be uncompressed with smartzip"; esac

You may notice that a special variable $1 is used above, which contains the first parameter value passed to the script. That is, when we run:

Smartzip articles.zip

$1 is the string articles.zip.

Related Article

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.