Linux ${} Character-channeling method summary

Source: Internet
Author: User

A summary of how Linux character channeling is intercepted


1. Summary of Commands


    • ${target-string#*sub-string}

    • ${target-string##*sub-string}


    • ${target-string%sub-string*}

    • ${target-string%%*sub-string*}


----------------------------------------------------------------------------


    • ${target-string:start-index:string-numbers}

    • ${target-string:start-index}


    • ${target-string:0-start_index:string-numbers}

    • ${target-string:0-start_index}


2. Summary of examples


st1= ' Http://www.baidu.com/image/image.png '


    • From the left side of the st1, cut off the left part of the position where the character first appears, leaving the right part intact and not containing '/'.

# echo ${st1#*/}/www.baidu.com/image/image.png


    • From the left side of the st1, cut off the left part of the last occurrence of this character, leaving the right part and not containing the '/'.

# echo ${st1##*/}image.png

----------------------------------------------------------------------------


st1= ' Http://www.baidu.com/image/image.png '


    • From the right side of the st1, cut off the right part of the first occurrence of the character, leaving the left part intact and not containing the '/'.

# echo ${st1%/*}http://www.baidu.com/image


    • From the right side of the st1, cut off the right part of the last occurrence of this character, leaving the left part intact and not containing '/'.

# echo ${st1%%/*}http:


-----------------------------------------------------------------------------


st1= ' Http://www.baidu.com/image/image.png '


    • From the left side of St1, start with the first character {0} and intercept {4}4 characters.

# echo ${st1:0:4}http


    • From the left side of the ST1, cut down 7 characters and keep the right part

# echo ${st1:7}www.baidu.com/image/image.png


---------------------------------------------------------------------------------------


st1= ' Http://www.baidu.com/image/image.png '


    • Start with the 10th character {0-10} on the right side of St1 and intercept 6 characters.

# echo ${st1:0-10:6}/image #不是ge. png because it is a 10th character from the right of the first, that is, 6 characters from the '/'.


    • Start with the 10th character {0-10} on the right side of ST1 and intercept all the characters on the right.

# echo ${st1:0-10}/image.png


3. Memory methods


    • Be sure to divide the intercept, or cut off.

    • There are 5 symbols, ' # ' # # '% ' of percent '    


#

This article is from the "Frog Technology Archive" blog, so be sure to keep this source http://frogtwo.blog.51cto.com/3805708/1939143

Linux ${} Character-channeling method summary

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.