Shell string interception, shell string Interception

Source: Internet
Author: User

Shell string interception, shell string Interception

1. The variable var starts from the npos in [0, length-1] bits, and truncates num characters from the left to the right:

$ {Var: npos: num}

Conclusion: If npos <0, the result is the original var value;

If npos> length (var)-1, the result is an empty string;

If the actual number of characters is less than num, the return value is based on the actual number of characters.

2. The variable var is truncated forward/backward Based on the specified string {first appearance, last appearance:

$ {Var ### * string} # extract from left to right and the last string

$ {Var # * string} # extract from left to right and the first string

$ {Var % string *} # extract from right-> left and the last string

$ {Var % string *} # extract from right-> left and the first string

Summary: For the # truncation character, the wildcard * is on the left side of the string and is intercepted from left to right;

For the % truncation character, the wildcard * is on the right of the string and is intercepted from the right to the left;

A single truncation character indicates the first occurrence position, and a double truncation character indicates the last occurrence position.

3. If you have time, summarize other methods ......

 

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.