时间:2023-06-02 16:16:41 来源: 人气:
例子:, 1., file_jpg="sample.jpg", name=${file_jpg%.*}, echo File name is $name, File name is sample, 2., file_jpg="sample.jpg", extension=${file_jpg#*.}, echo Extension is $extension, File name is jpg, 3., file_name="www.google.com", echo ${file_name%%.*}, www, 4., file_name="www.google.com", echo ${file_name##*.}, com, 说明:, ${file_jpg%.*}的含义是:从$file_jpg中删除位于%右侧的通配符所匹配的字符串,通配符从右向左进行匹配。, ${file_jpg#*.}的含义是:从$file_jpg中删除位于#右侧的通配符所匹配的字符串,通配符从左向右进行匹配。, %属于非贪婪操作,它从右到左找出匹配通配符的最短结果。, %%属于非贪婪操作,它从右到左找出匹配通配符的最长结果。, #属于非贪婪操作,它从左到右找出匹配通配符的最短结果。, ##属于非贪婪操作,它从左到右找出匹配通配符的最长结果。,