#!/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