"Drip" LINUX string interception __linux

Source: Internet
Author: User
Usage: ${str%word} #最大限度的获取word左边的子串 ${str%%word} # Minimum gets the substring ${str#word} to the left of Word #最大限度的获取word右边的子串 ${str# #word} #最小限度的获取word右边的子串 ${#str} #获取字符串长度
Example:
file= "Abc.def.ghi"
#最大限度获取. * substring on the left
> a=${file%.*}
> Echo $a
abc.def
#最小限度获取. * Left substring
> a=${file%%.*}
> Echo $a
ABC
#最大限度获取 *. substring on right side
> a=${file#*.}
> Echo $a
def.ghi
#最小限度获取 *. substring on the right
> a=${file##*.}
> Echo $a
ghi
#获取长度
> length=${#file}
> Echo $length
#################### ################################
#字符串下标从0开始, 0 represents the first character, and 0-1 represents the first character on the right
##################################
the ################## #从左边第2个 (the array subscript 1) starts the interception, intercepting the length of 2
> Echo ${file:1:2}
BC
#从左边第2个开始截取到结尾
> Echo ${file:1}
Bc.def.ghi
#从右边第三个开始截取, intercept length 2
> Echo ${file:0-3:2}
gh
# From the right third start intercept to the end
> Echo ${file:0-3}
Ghi


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.