Interception of Shell strings

Source: Internet
Author: User

directly on the code.

1linux- About:/Install#Cat 3.SH 2#!/bin/SH3Str=HelloWorld4 Echo 'STR = ='$STR5 6 Echo${STR:5:5} # ==Echo${STR:5} #结果为World7 Echo${STR:5} # Use: ${str:begin:len} #结果为World 8 9 ExprSubstr"$STR" 6 5 #结果为World Ten  One Echo$STR |awk '{print substr ($STR, 6,5)}' #结果为World  A  - Echo$STR |Cut-c6-Ten #结果为World  -  the#Expr$STR:'\(.\\).*' -  - Echo$STR |DDbs=5Count=1 2>/dev/null #结果为Hello, but with no line breaks  -  + Echo "" - Echo${str##*Hello} #结果为World #从左向右截取最后一个string后的字符串 + Echo${str#*Hello} #结果为World #从左向右截取第一个string后的字符串 A  at Echo${str%%world*} #结果为Hello #从右向左截取最后一个string后的字符串 - Echo${str%world*} #结果为Hello #从右向左截取第一个string后的字符串 -  -#ls-al |Cut-D"."-f2 #这里可以得到文件夹的后缀名

Interception of Shell strings

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.