Linux Bash shell string split substring etc (RPM)

Source: Internet
Author: User

Original 52779364

The problem with script development is that the string splitting operation in the original Java (substring indexof, etc.) does not know what to do (e.g./a/b/c/d.txt I want to know the name of the file)

Query information that the shell can use identifiers to do the split string, including substring (0,index) and substring (index,last)

${VAR#*SUBSTR} Removes the last occurrence of a substring from 0 to substr

${VAR##*SUBSTR} will delete the position where the substr begins to the end of the string

${var%substr*} Removes the last part of the string where the string ends

${var%%substr*} will delete the first occurrence of the string to the end of the section

[Plain]View PlainCopy
    1. A= "/a/b/c/d.txt"
    2. b= "/"
    3. echo ${a#* $b}

will return

A/b/c/d.txt

[Plain]View PlainCopy
    1. A= "/a/b/c/d.txt"
    2. b= "/"
    3. echo ${a##* $b}


will return

D.txt

[Plain]View PlainCopy
    1. A= "/a/b/c/d.txt"
    2. b= "/"
    3. echo ${a% $b *}

will return

/a/b/c

[Plain]View PlainCopy
    1. A= "/a/b/c/d.txt"
    2. b= "/"
    3. echo ${a%% $b *}


will return empty

Linux Bash shell string split substring etc (RPM)

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.