Shell percent, ##,#,% usage

Source: Internet
Author: User

#!/bin/bash# @author: goooood#[email protected] #对文件名的截取分析 #file= "/dir1/dir2/dir3/my.file.txt" "#  left First" " ##  left   greedy " "  *  all matches   "#以第一个点删除左边echo  ${file#*.}   #输出: file.txt# Delete the left echo ${file##* at the last point.} #输出: txt# left encounters the first 3 all remove echo ${file#*3} #输出:/my.file.txt# left start 3 End all remove #file= "/dir1/dir2/dir3/my3.file.txt" Echo  ${FILE##*3} #输出:. file.txt# take off all left to/  (greedy) echo ${file##*/} #输出: My.file.txt "%  Right First" "%%  right   Greed "#拿掉最后一个/And Right echo ${file%/*} #输出:/dir1/dir2/dir3# take off the first point and the right echo ${file%%.*} #输出:/dir1/dir2/dir3/ my# take off a/  and the right echo ${file%%/*} #输出:  Empty # example: Take off the right first 3#file= "/dir1/dir2/dir3/my3.file.txt" echo $ {file%3*} #输出:/dir1/dir2/dir3/my# example: Take off right start encounter 3 remove #file= "/dir1/dir2/dir3/my3.file.txt" echo ${file%%3*} #输出:/ dir1/dir2/dir# cut to the right of. File.txt echo ${file%.file.txt} #等于echo  ${file%%.file.txt} #输出:/dir1/dir2/ Dir3/my#file= "/dir1.file.txt/dir2/dir3/my3.file.txt" #%%  can be greedy echo ${file%%.file.txt*} #输出:/dir1#filE= "/dir1.file.txt/dir2/dir3/my3.file.txt" #%  match on the right first echo ${file%.file.txt*} #输出:/dir1.file.txt/dir2/ Dir3/my3


This article is from the "Goooood" blog, make sure to keep this source http://goooood.blog.51cto.com/5060201/1711123

Shell percent, ##,#,% usage

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.