string of Shell intercept variable

Source: Internet
Author: User

From: http://blog.sina.com.cn/s/blog_7c95e5850100zpch.html

Suppose there is a variable var=http://www.linuxidc.com/test.htm a # Intercept, delete the left character, and leave the right character. echo ${var#*//} where  var  is the variable name,#  number is the operator,*//  means delete the first  //  and all characters to the left from the left to delete   http://result is  :www.linuxidc.com/test.htm  two  ##  intercept, delete left character, retain right character. echo ${var##*/}##*/  means delete the last (rightmost)  /  and all characters on the left, starting from the left  http://www.linuxidc.com/           result is  test.htm three  %, delete the right character, leave the left character echo ${var%/* }%/*  means starting from the right, deleting the first  /  and right character result is: http://www.linuxidc.com four  %%  intercept, delete the right character, leave the left character Echo  ${var%%/*}%%/*  to start from the right, delete the last (leftmost) one  /  and right character result is: http: Five   start with the first character on the left and the number of characters echo ${ Var:0:5} where the  0  represents the first character on the left,,5  represents the total number of characters. The result is: http: Six   starting from the first few characters on the left, until the end. Echo ${var:7} where  7  represents the 8th character on the left, starting at the end. The result is  :www.linuxidc.com/test.htm seven   starting with the first character on the right and the number of characters Echo ${var:0-7:3} where  0-7  Represents the number of characters from the right side, starting with the seventh character,3 . The result is: Test eight   start from the first character on the right, until the end. Echo ${var:0-7} means starting from the seventh character on the right until the end. The result is: test.htm Note: (The first character on the left is denoted by  0 , rightThe first character of the edge is represented by  0-1 ) This article originates from the  linux commune website (www.linuxidc.com)    original link: http://www.linuxidc.com/ Linux/2010-12/30625.htm

String of Shell intercept variable (GO)

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.