Interception of Shell strings

Source: Internet
Author: User
Tags first string

1, variable var from npos∈[0, Length-1] bit start, from left-to-right intercept num characters:

    ${var:npos:num}

Summary: If NPOs < 0, the result is var original value;

If NPOs > Length (Var)-1 Then the result is an empty string;

If the character does not actually meet the NUM bit, it is returned as the actual character.

2, variable var by the specified string {The first occurrence, the last occurrence}, the forward/backward start interception:

${var##*string} # From left-to-right, the last string begins to intercept

${var#*string} # From left-to-right, the first string begins to intercept

${var%%string*} # from right-to-left, the last string begins to intercept

${var%string*} # from right-to-left, the first string begins to intercept

    Summary: For the # Intercept, the wildcard character * is on the left side of string and follows a left-to-right intercept;

For the% intercept, the wildcard character * is to the right of the string and follows the right-to-left intercept;

A single interceptor represents the first occurrence of a position, and a double-intercept indicates the last occurrence.

3, free to summarize other ways ...

Interception of Shell strings

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.