Linuxshell script Base 6-CASE...ESAC usage and wildcard characters

Source: Internet
Author: User

1, the use of CASE...ESAC

#!/bin/Bashecho"Please enter a number to choose a different way to display files and directories:"Echo"1-Normal display"Echo"2-Detailed display"Echo"3-Show hidden files"Echo"4-Exit"Read NUM1 Case$num 1inch        1) LS;; 2) LS-l;; 3) LS-LA;; 4) exit;; Esac

2. Wildcard characters

 #!/bin/bashecho   "  Please enter the filename to extract   read file1  case   ${file1##*.}   " in                  GZ) tar -XZVF ${file1}        ;;        Zip) unzip ${file1};;  *) echo    > Sorry, it's not possible to decompress this format   "  exit ;; Esac  

${file1##*.} The interception of a string means to intercept the file name "." After the string
For example: GZ after test.gz intercept, zip after Test.zip intercept

* Wildcard, representing all matches of 0 or more than 0

mkdir test
Zip Test.zip Test
TAR-CZF test.tar.gz Test

Linuxshell script Base 6-CASE...ESAC usage and wildcard characters

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.