Shell some methods

Source: Internet
Author: User

String interception from the original address: http://www.jb51.net/article/56563.htm

One: string interception

There are VAR variables:

var=http://www.aaa.com/123.htm

1. # Intercept, delete the left character, leave the right character.

echo ${var#*//}
Www.aaa.com/123.htm

2. # # Intercept, delete the left character and leave the right character.

echo ${var##*/}123. htm

3.% Intercept, delete right character, leave left character

echo ${var%/*}http://www.aaa.com

4. The percent number intercept, delete the right character, leave the left character

echo ${var/*}http:

5. Start with the first few characters on the left and the number of characters

echo ${var:0:5} #其中的 0 represents the beginning of the first character on the left and 5 represents the total number of characters.
http

6. Starting from the first few characters on the left, until the end

echo ${var:7}   7  means the 8th character on the left begins, until the end. www.aaa.com/123. htm

7. Start with the first few characters on the right and the number of characters

echo ${var:0-7:3}                0-7 means the seventh character starts at the right,3  Represents the number of characters.  123

8. Start with the first few characters on the right and continue to the end.

echo ${var:0-7}                    #表示从右边第七个字符开始, until the end.  123. htm

To judge a string containing a relationship from: http://www.cnblogs.com/ginsonwang/p/5525340.html

Two: The judgment string contains

1

Stra="Long String"StrB="string"result=$ (echo $strA | grep"${STRB}")if[["$result"!=""]]then Echo"include"ElseEcho"does not contain"fi

2

Stra="helloworld"strB="low"if [[$strA =~ $strB]] Then    " contains "else  "does not contain     " fi

3

A="helloworld"B="low"if [[$A = = * $B * ] ]then    " contains "else  "does not contain     " fi

4

thisstring="1 2 3 4 5"  # source string searchstring="1 2"  # Search string case in      *"$searchString"*) echo Enemy Spot;    *) echo nope;; ESA

5

string_a=$1string_b=$2if [[${string_a/${string_b}//} = = $STRING _ A] then was not substring.                echo N        return0    else is          substring.        echo Y        return1    fi

Shell some methods

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.