Shell simple Use (v) three of the variables

Source: Internet
Author: User

Shell variable Handling

1. Variable deletion

${var#key} Delete the shortest match from the beginning

${var# #key} Delete the longest match from the beginning

  

2. Variable deletion

${var%key} Delete shortest match from tail forward

${var%%key} deletes the longest match from the tail forward

  

3. Variable substitution

${var/old/new} replaces the first match

${var//old/new} Replace all matches

  

4. Replacing and assigning values

A. ${var-init} to variable var, existence is persisted, no then assignment init

  

B. ${var:-init} to variable Var, a non-null value is persisted, no or null value is assigned to Init

  

C. ${var+expr} If the variable var does not exist, it is not assigned, and if the variable var exists, the value expr

  

D. ${var:+expr} if the variable var does not exist or is NULL, the value is not assigned, and if Var is a non-null value, expr is assigned

  

E. ${var=expr}

  

F. ${var:=expr}

  

G. ${var?expr}

    

H. ${var:?expr}

  

Shell simple Use (v) three of the variables

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.